Android Question make a checkbox checked all the time

Mehrzad238

Member
hi all,
I have a series of checkboxes that user can only check one checkbox and at starting one of the checkboxes are checked.
how can I make that checked box always checked, even user try to uncheck the one that checked
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why aren't you using RadioButtons?

Making CheckBoxes behave as RadioButtons:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private MyCheckboxes As List
End Sub

Public Sub Initialize
    
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MyCheckboxes.Initialize
    For Each v As B4XView In Root.GetAllViewsRecursive
        If v Is CheckBox Then
            MyCheckboxes.Add(v)
        End If
    Next
End Sub

Private Sub CheckBox_CheckedChange(Checked As Boolean)
    Dim current As B4XView = Sender
    If Checked = False Then
        For Each chk As B4XView In MyCheckboxes
            If chk.Checked Then Return
        Next
        current.Checked = True
    Else
        For Each chk As B4XView In MyCheckboxes
            If chk <> current Then chk.Checked = False
        Next
    End If
 
Upvote 0
Top