B4J Question B4J How to detect mouse over label using only one sub?

eljare24

Member
How can I tell when the mouse is over a label created by code? There are actually 26 labels using a single subroutine. In other words, how can I avoid using a separate subroutine for each label, since there are so many?.

I'm working on b4j. b4xpages

Thanks in advance!

Javier
 

teddybear

Well-Known Member
Licensed User
When creating labels, assign the same event name to all 26 labels.
B4X:
    Dim labels As Label
    For i=1 To 26
        labels.Initialize("Label")
        labels.Tag=i
        labels.Text="label"&i
        Root.AddView(labels, ......)
    Next
    
Private Sub Label_MouseMoved (EventData As MouseEvent)
    Dim lbl As Label=Sender
    Log(lbl.Tag)
    Log(lbl.Text)
End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
also there are specific events, like MouseEntered & MouseExited
 
Upvote 0
Top