Android Question Identify panel childs click

Guenter Becker

Active Member
Licensed User
Hello,
This is a B4A Question.
I have a panel and I generate more ore less labels as child views.
Each label is initialized with the same click event 'Label' because I do not want to have a separate click sub per label.
If the user clicks on a label the event is fired and the 'sub Label_click' is called..

Question:
Inside the sub Label_click is there a possibility to detect which of the label was clicked? Please give Codesnipped. Thank you.
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Button1_Click
    Dim btn As Button = Sender
    
End Sub
btn is the Clicked button
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Inside the sub Label_click is there a possibility to detect which of the label was clicked?
test:
B4X:
'id Label
Label1.Tag = 1
Label2.Tag = 2

B4X:
Private Sub Label_Click
    Dim v As Label = Sender
    Select v.tag
        Case 1
            Log(v.text)
        Case 2
            Log(v.text)
    End Select
End Sub
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Wow, quick answer thank you.
Don't know what is going into me! Oparras solution is so easy but I not hit on it.
I think sometimes I loose parts of my brain.
Again Big Thank you.
 
Upvote 0

BasicBert

Member
Licensed User
Longtime User
I always avoided using Sender because I didn't really understand the concept and was fine with creating different subs for each button or label clicked.
Now I'm in need of reacting to clicks of more buttons or labels then before, so I began looking into the Sender object. Above code really helped a lot to understand what's happening.

As in the demo I can make a series of labels in code, and when clicked I am able to set a new Text for the label, like this :

B4X:
Private Sub Label_Click
    Dim v As B4XView = Sender
    xui.MsgboxAsync("ID Tag: " & v.tag, "Label Click")
    v.Text = "Hello world!"
End Sub

But now I would like to change the Text for all or some labels without being clicked on.
How do I reference any or all labels in the demo and change the Text (or any other) property?
 
Upvote 0

BasicBert

Member
Licensed User
Longtime User
toby,
Thanks for reacting so fast.
This would be very simple, if it did the trick. I tried, but it doesn't work as I hoped. The labels Label1 and Label2 throw an error because they have not been declared (and initialized) .
Any other suggestion ?
 
Upvote 0
Top