Guenter Becker Active Member Licensed User Longtime User Dec 22, 2021 #1 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.
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 Dec 22, 2021 #2 B4X: Copy Sub Button1_Click Dim btn As Button = Sender End Sub btn is the Clicked button Upvote 0
TILogistic Expert Licensed User Longtime User Dec 22, 2021 #3 Inside the sub Label_click is there a possibility to detect which of the label was clicked? Click to expand... test: B4X: Copy 'id Label Label1.Tag = 1 Label2.Tag = 2 B4X: Copy 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
Inside the sub Label_click is there a possibility to detect which of the label was clicked? Click to expand... test: B4X: Copy 'id Label Label1.Tag = 1 Label2.Tag = 2 B4X: Copy 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
TILogistic Expert Licensed User Longtime User Dec 22, 2021 #4 demo: Attachments views.zip views.zip 10 KB · Views: 438 Upvote 0
Guenter Becker Active Member Licensed User Longtime User Dec 22, 2021 #5 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
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.
M Mahares Expert Licensed User Longtime User Dec 22, 2021 #6 oparra said: demo: Click to expand... Since you like to outdo other's code with yours at times, here is one for you: Instead of: Code: Copy Private Sub Label_Click Dim v As B4XView = Sender xui.MsgboxAsync("ID Tag: " & v.tag, "Label Click") End Sub Use: Code: Copy Private Sub Label_Click xui.MsgboxAsync("ID Tag: " & Sender.As(B4XView).tag, "Label Click") End Sub Upvote 0
oparra said: demo: Click to expand... Since you like to outdo other's code with yours at times, here is one for you: Instead of: Code: Copy Private Sub Label_Click Dim v As B4XView = Sender xui.MsgboxAsync("ID Tag: " & v.tag, "Label Click") End Sub Use: Code: Copy Private Sub Label_Click xui.MsgboxAsync("ID Tag: " & Sender.As(B4XView).tag, "Label Click") End Sub
B BasicBert Member Licensed User Longtime User Jun 4, 2023 #7 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 : Code: Copy 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
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 : Code: Copy 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?
toby Well-Known Member Licensed User Longtime User Jun 4, 2023 #8 Label1.text="new text 1" Label2.text="new text #2" Upvote 0
B BasicBert Member Licensed User Longtime User Jun 4, 2023 #9 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
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 ?