Android Question Create button in runtime

MarkusR

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    
    Type Pos(x As Int,y As Int)

End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)

    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Test")

    Buttons

B4X:
Sub Buttons
        
    For x = 0 To 2
    For y = 0 To 4
        Dim ButtonX As Button
        Dim PosX As Pos
            PosX.x = x
            PosX.y = y
            ButtonX.Initialize("Button")
        ButtonX.Tag = PosX
        Activity.AddView(ButtonX,x*33%x,y*20%y,33%x,20%y)         
    Next
    Next
    
End Sub

Sub Button_Click
    
    Dim Button1 As Button
    Button1 = Sender
    
    Dim Pos1 As Pos
    Pos1 = Button1.Tag   
        
    Log(Pos1.x & " " & Pos1.y)
    
End Sub
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
if Y value is Dynamic,then how to calculate %x and %y ???

I means,It should be scrollable if rows is greater than 15.........
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
That would be fine too

B4X:
Sub Button_Click
    
    Dim Button1 As Button
    Button1 = Sender
    
    Log(Button1.Left & " " & Button1.Top)
    
End Sub
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
if Y value is Dynamic,then how to calculate %x and %y ???
then u use dip as size, it will have at all devices the same height.
B4X:
y*100dip
 
Upvote 0
Top