B4J Question How do I add an on-click event to a checkbox or other view that sdoesn't have the mouse events

mangojack

Expert
Licensed User
Longtime User
? unsure if this solves your wish.
B4X:
Sub CheckBox1_MouseClicked (EventData As MouseEvent)
    Log("CheckBox Clicked !")
End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Just set a global flag when you want to change the value programmatically and in the CheckedChange event test and ignore

B4X:
' in globals
Dim chk_box_flag as Boolean = false

'in your code
...
' change by code
    chk_box_flag = True
    chk_box.Checked = Not(chk_box.Checked)

...
Sub chkbox_CheckedChange(Checked As Boolean)
    If chk_box_flag Then 
        chk_box_flag = False
        Return
    End If
    Log("value changed") ' only shows if you click checkbox
    chk_box_flag = False
End Sub
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
? unsure if this solves your wish.
B4X:
Sub CheckBox1_MouseClicked (EventData As MouseEvent)
    Log("CheckBox Clicked !")
End Sub
Just set a global flag when you want to change the value programmatically and in the CheckedChange event test and ignore

B4X:
' in globals
Dim chk_box_flag as Boolean = false

'in your code
...
' change by code
    chk_box_flag = True
    chk_box.Checked = Not(chk_box.Checked)

...
Sub chkbox_CheckedChange(Checked As Boolean)
    If chk_box_flag Then
        chk_box_flag = False
        Return
    End If
    Log("value changed") ' only shows if you click checkbox
    chk_box_flag = False
End Sub
Hi,

Yes I have been setting a flag to true after initialisation. It helped, but it didn't fix every situation.

Thans
Rob
 
Upvote 0
Top