Android Question How to create many objects in code using a model

AlexOfOz

Active Member
Licensed User
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.

Thank-you.
Alex
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
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.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
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.

Thanks,
Alex
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
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.
 
Last edited:
Upvote 0

AlexOfOz

Active Member
Licensed User
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.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
tips: dynamic controls

 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
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.

 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
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
 
Last edited:
Upvote 0
Top