Label Click Response

Guardian17

Active Member
Licensed User
Longtime User
I have 3 labels on a panel that I want to respond to a click event. This is the hierarchy of the Objects:

Activity
Panel1
Panel2
Label1
Label2
Label3
(e.g.: Labels 1,2,3 are on Panel2 which is on Panel1 which is part of Activity).

I am able to generate a click event for Panel2 when I click on Label1/2/3, but if I use the Label name itself (e.g. Label1_Click), I do not get a click event.

Labels1/2/3 are added programmatically, not placed in Designer. Panel1 and Panel2 were placed in Designer. Is there some limitation to only allowing Click Events on items placed in Designer?
 

Guardian17

Active Member
Licensed User
Longtime User
Method of Initialization

This is in my Activity_Create Module for one label:

B4X:
Dim gr As GradientDrawable
Dim Cols(2) As Int
Dim ModePanelLbl As Label
ModePanelLbl.Initialize("")
ModePanel.AddView(ModePanelLbl,7dip,6dip,20dip,20dip)
Cols(0) = Colors.RGB(150,150,150) ' Grayish Label
Cols(1) = Colors.RGB(50,50,50)
gr.Initialize("TL_BR", Cols)
gr.CornerRadius = 5dip
ModePanelLbl.Background = gr
ModePanelLbl.TextColor = Colors.White
ModePanelLbl.BringToFront

ModePanel is what I had called "Panel2" previously, and ModePanelLbl is any one of Label1,2,3 previously.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If your label needs a click event, you need to initialize it with an event name like this:
B4X:
Dim ModePanelLbl As Label
ModePanelLbl.Initialize("ModePanelLbl")

Sub ModePanelLbl_Click
   msgbox("I am a label that just got clicked","")
End Sub
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
or you could set up and invisible buttons over top of the labels (as in enabled, visisble but alpha at 0). Then just use the buttons for whatever. Although, not sure what the difference is.
 
Last edited:
Upvote 0

Guardian17

Active Member
Licensed User
Longtime User
Thank you

I always wondered why the initialization of a Label had an EventName specified :eek:. Worked just fine.

Thanks for the responses.
 
Upvote 0
Top