Android Question Looping Click EVENTS

Is it possible to loop click events?
For example, if you declare the buttons like this in Sub Global. How would call the click_events for each button?
B4X:
Private btn(3) as Button
 

KMatle

Expert
Licensed User
Longtime User
You mean 3 buttons and just one click event sub?

1. Give every button the SAME event name (example: "MyButton" in Initialize)
2. Give every button a different tag (example 1 to 10 in a loop)
3. In the click event sub (example: MyButton_Click)

B4X:
Sub MyButton_Click
    Dim b As Button
    b=Sender 'the sending button :-)
  
    Select b.Tag 'if you have set the tag to 1 and 2. Change if you have set it to another value...
        Case "1"
            'code for button 1
        Case "2"
            'code for button 2
    End Select
  
End Sub

This works for "all" views!

Hint: If you create views by code then store them in e.g. a list to retrieve them later (= Button number 5). Otherwise you have to get it from the parent view which is possible, too but not recommended.
 
Upvote 0
Top