Capturing events for an array of views.

skcud

Member
Hey guys. I have 3 sets of arrays of labels totalling a potential of 90 labels being utilised. I need to capture a 'click' event for each of these labels. Please, please tell me there is a way of doing this without having to write out the code for a click event for all 90 labels.
Thanks for your time.
:sign0085:
 

klaus

Expert
Licensed User
Longtime User
How do you create your labels ?
The name has no importance, what yo need is:
- to Dim each label
- initialize each label with the SAME event name for all labels
- set a different Tag property for each label, allowing to know what Label eaised the Click event.

You find an example of a keyboard with buttons sharing the same click event in chapter 3 Second program in the Beginner's Guide.

Best regards.
 
Upvote 0

skcud

Member
Thank you for the response.
So I have done what you said and have now set tag values for each of my labels. One of my arrays is YVV(x) and they all have the event name "YVV"
So I have started a new sub with:
B4X:
Sub YVV_Click
How do I determine the tag value of the label that was clicked?
Thanks again.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
You need to use the Sender keyword in your sub - that is a pointer to the object that called the sub:
B4X:
Sub YVV_Click
   Dim buttonId As String
   btn = Sender
   ButtonId = btn.Tag 
   .................
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…