Other [Self Answer] Triggering checkbox in a panel by pressing the panel

Fusseldieb

Active Member
Licensed User
Longtime User
Hi,
i have searched all over this forum and haven't found anything. Because of that I want to share how you can trigger a checkbox, pressing the panel where the checkbox is in.

When you initialize the panel programatically, define a trigger event like this:
B4X:
Dim DynPanel As Panel
DynPanel.Initialize("DynPanel") '<-- Specify the trigger event!
...
If you have this done, you must catch the triggering event, by using this code:
B4X:
Sub DynPanel_Touch(Action As Int, X As Float, Y As Float)
Select Action
Case Activity.ACTION_UP

Dim PressedPanel As Panel=Sender
Dim CB As CheckBox=PressedPanel.GetView(1)
CB.Checked=True

End Select
End Sub
In my case the index of the Checkbox is "1", but it can vary. If you want to know on which index your control is stored, just use this:
B4X:
Sub DynPanel_Touch(Action As Int, X As Float, Y As Float)
Select Action
Case Activity.ACTION_UP

For Each v As View In SelectedPanel.GetAllViewsRecursive
Log(v)
Next

End Select

log1.png

In the image above you can see the output that the Log will give. The red text shows which index it is.
After you have discovered the index, delete this code and use the first one, specifying the index...
Now when you touch the Panel the Checkbox will be triggered ;)
 
Top