B4J Question Problem triggering event of view array [solved]

Didier9

Active Member
Licensed User
I have something very similar working in B4A but this simple project in B4J shows my problem.
I must be missing something in the declaration and the click event for the checkboxes is not triggered.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 200
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private cb(), CheckBox1, CheckBox2, CheckBox3, CheckBox4 As CheckBox
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("main") 'Load the layout file.
    MainForm.Show
    cb = Array As CheckBox( CheckBox1, CheckBox2, CheckBox3, CheckBox4)
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub cb_Click
    Dim i As Int
    Dim c As CheckBox
    c = Sender
    For i=0 To cb.Length-1
        cb(i).checked = False
    Next
    cb(c.Tag).Checked = True
End Sub
I have attached a complete project cut to the bone.
 

Attachments

Daestrum

Well-Known Member
Licensed User
You need to change the event name for each Checkbox in the designer so it calls cb not CheckBox1,CheckBox2 ...

also tag refers to the next checkbox ( should be zero based )
B4X:
cb(c.Tag - 1).Checked = True
 

Daestrum

Well-Known Member
Licensed User
The class extends another b4j class so it gains action and click as events from the parent class.
 

Didier9

Active Member
Licensed User
For a CheckBox, CheckChanged is the only event in B4J. See: https://www.b4x.com/b4j/help/jfx.html#checkbox
Not true.
I added this:
B4X:
Sub CheckBox1_Click
    MainForm.Title = "CheckBox1 clicked"
End Sub

Sub CheckBox2_Click
    MainForm.Title = "CheckBox2 clicked"
End Sub

Sub CheckBox3_Click
    MainForm.Title = "CheckBox3 clicked"
End Sub

Sub CheckBox4_Click
    MainForm.Title = "CheckBox4 clicked"
End Sub
and that part works as expected.
 

Didier9

Active Member
Licensed User
You need to change the event name for each Checkbox in the designer so it calls cb not CheckBox1,CheckBox2 ...

also tag refers to the next checkbox ( should be zero based )
B4X:
cb(c.Tag - 1).Checked = True
That was exactly what was wrong with it.
Of course, the tag was off by one, it's obvious and I would have found that quickly once the first error was corrected.

Thanks a bunch!
 
Top