Android Question How to programmatically click on all dynamically created buttons

danijel

Active Member
Licensed User
Longtime User
Hi, here is simplified version of my problem.
I want to programmatically click on all dynamically created buttons.
Obviously, my commented attempt (MyButton_Click) is not working.
I have no idea how this could be done. Any suggestions?
B4X:
Sub Activity_Create(FirstTime As Boolean)
   For i=0 To 9
     Dim MyButton As Button
     MyButton.Initialize("MyButton")
     Activity.AddView(MyButton, 0, 10%y*i, 100%x, 10%y)
     MyButton.Text=Rnd(10,20)
   Next
   'MyButton_Click
End Sub

Sub MyButton_Click
   Dim b As Button
   b=Sender
   For i=b.Text To 0 Step -1
     b.Text=i
     Sleep(1000)
   Next
End Sub
 

derez

Expert
Licensed User
Longtime User
B4X:
Sub Globals
    Dim mybutton(10) As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    For i=0 To 9
        mybutton(i).Initialize("MyButton")
        Activity.AddView(mybutton(i), 0, 10%y*i, 100%x, 10%y)
        mybutton(i).Text=Rnd(10,20)
    Next
   
    MyButton_Click
End Sub

Sub MyButton_Click
    For i= 9 To 0 Step -1
        mybutton(i).Text = i
        Sleep(1000)
    Next
End Sub
 
Upvote 0
Top