B4J Question Detect a click on a label on a listview

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

Thank you for your replies.

How do I detect a click on a label on a listview in B4J?

Best regards.

Sandy
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you are just adding strings to the listview then there are no labels.

You need to explicitly create the labels and add them:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private ListView1 As ListView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNIFIED")
   MainForm.RootPane.LoadLayout("1")
   MainForm.Show   
   For Each s As String In Array("item 1", "item 2", "item 3")
     Dim lbl As Label
     lbl.Initialize("lbl")
     lbl.Text = s
     ListView1.Items.Add(lbl)
   Next
End Sub

Private Sub lbl_MouseClicked (EventData As MouseEvent)
   Dim lbl As Label = Sender
   Log($"Label: ${lbl.Text} was clicked"$)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…