Android Question Getting checkbox reference from called event handler

Alessandro71

Well-Known Member
Licensed User
Longtime User
I have a dynamically populated ScrollView containing a list of checkboxes, and defined an common handler for all of them

For i = 0 To (filelist.Size - 1 )
Dim chk As CheckBox
chk.Initialize("chk")
chk.Gravity = Gravity.CENTER_VERTICAL
chk.Text = filelist.Get(i)
chk.TextSize = textsize
lstChecks.Add(chk)

pnl.AddView(chk, 0, height * i, 100%x, height)
Next

Sub chk_LongClick
???
End Sub

i want to trap a longclick event, but when the sub is called, how can i access the triggered checkbox?
using the Me object produces a compile error
 

LucaMs

Expert
Licensed User
Longtime User
Se me fai fatica' a scrive in inglese e poi sei italiano... :D

First of all, Checkboxes do not raise the LongClick event; they have only CheckedChange.

Anyway, in an event routine like that you should use the Sender object, which is automatically passed to the routine:

B4X:
Sub chk_LongClick
   Dim chk As CheckBox = Sender
' here you can handle the cb "selected"
End Sub

B4X:
Sub chk_CheckedChange(Checked As Boolean)
   Dim chk As CheckBox = Sender
   ' ...
End Sub


I'm pretty sure that there is a way (reflector or java object) to add a long click event (a listener) also to Checkboxes... I have to search for it
 
Last edited:
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
Actually I already receive longclick event from check boxes.
They just don't get checked, but that’s ok for my use case

Grazie
 
Upvote 0
Top