Maybe a silly question, but I can't find the answer.
How do I create, in the code, many objects by using a model object as a reference? In this case I need to create many PANELs which are all the same apart from their location on the screen.
Can you explain what you mean by "a model object"? Otherwise you can do what you describe with a subroutine and a layout - just pass the corner coordinates.
Brian, what i mean is that i have created a "model" in the designer using rounded corners. l don't think i can do that in the code. i am creating a game that needs many of these.
I am not in a position to test anything out right now, but I feel that there is a way to do rounded corners in code. I would start by looking at casting the panel to a B4XView.
Alternatively create a transparent panel and load your layout.
Brian, I suspect your suggestion of "load your layout" is what I'm looking for. Call me simple, but i've never understood how to do that. i've tried to work it out many times in similar circumstances but have never been able to.
A simple custom view which creates a grid of panes. You can set the number of columns and rows. The panes are resized automatically when the GridManager is resized, make sure to use anchors in your layouts. In this example the same layout is loaded in each of the panes. You can of course load...
How do I create, in the code, many objects by using a model object as a reference? In this case I need to create many PANELs which are all the same apart from their location on the screen.
Custom views are designed to be added with the designer. It is however very simple to create a layout file with the custom view and load it multiple times. Tip: remove the call to AutoScaleAll from the designer script. Complete example: Sub Globals Private B4XSwitch1 As B4XSwitch End...
A bit late now, I know, but this is what I would have posted last night if I had been at my PC . . .
B4X:
Private Sub Activity_Touch (Action As Int, X As Float, Y As Float)
makeSpot(X, Y)
End Sub
Public Sub makeSpot(x As Int, y As Int)
Dim spot As Panel
spot.Initialize("")
Dim size As Int = 80dip
Dim a As Int = 40dip
Activity.AddView(spot, x - a, y - a, size, size)
spot.As(B4XView).SetColorAndBorder(xui.Color_Green, 0, 0, 40dip)
spot.LoadLayout("Layout") ' If required
End Sub