Android Question Crash: Unexpected event (missing RaiseSynchronousEvents) when using a checkbox as B4XView in B4XPages

doncx

Active Member
Licensed User
Longtime User
This is only a problem in B4A. In B4J it works. I haven't tried B4i

The problem appears related to checkbox as B4XView not having an mBase attribute.

It is only a problem in debug mode, but it stops execution and the app dies, preventing me from accessing the rest of the app in debug mode.

In two similar xCustomListViews: The one with B4XRadioButtons has no problem. The one with checkboxes as B4XViews dies.

For what it's worth, in both cases the views are also declared in Class_Globals (checkbox as B4XView, radio button as B4XRadioButton).

This Code Works:
Private Sub rdoItem_Checked
    Dim rb As B4XRadioButton = Sender
    Dim p1 As B4XView = rb.mBase.Parent
    If (rb.Checked) Then
        p1.SetColorAndBorder( xui.Color_RGB( 225, 225, 230 ), 4dip, xui.Color_RGB(210, 0, 35), 8dip)
    End If
End Sub

This code crashes in debug mode:
Private Sub cbxDiseaseItem_CheckedChange(Checked As Boolean)
    Dim cb As B4XView = Sender
    Dim p1 As B4XView = cb.parent 'Crashes here. Can't use mBase as it won't compile
    If (cb.Checked) Then
        p1.SetColorAndBorder( xui.Color_RGB( 241, 215, 177 ), 4dip, xui.Color_RGB(210, 0, 35), 8dip)
    End If
End Sub

Any assistance would be greatly appreciated.
 
Solution
Ok, I've figured this out. When the checkbox is tapped, then the sender is the checkbox. However, if the checkbox is programmatically checked then there is no sender.

The answer was to check for a Null sender and use some other mechanism to determine the checkbox parent when that was the case.

FWIW, the B4XRadioButton _Checked event always has sender, even when programmatically checked. So it's different (and better?).

doncx

Active Member
Licensed User
Longtime User
Ok, I've figured this out. When the checkbox is tapped, then the sender is the checkbox. However, if the checkbox is programmatically checked then there is no sender.

The answer was to check for a Null sender and use some other mechanism to determine the checkbox parent when that was the case.

FWIW, the B4XRadioButton _Checked event always has sender, even when programmatically checked. So it's different (and better?).
 
Upvote 0
Solution
Top