Android Question Check only one checkbox

DonManfred

Expert
Licensed User
What is "the same event"?

It depends on how you are managing your views/checkboxes.
Hold a reference to all checkboxes you want to "use" (put them in a map or a list or an array) and then ieterate through all, set them unchecked.

As you are not providing any example project we just can guess.

Start with providing a sample project and a more detailed question.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private CheckBox1 As CheckBox
    Private CheckBox2 As CheckBox
    Private CheckBox3 As CheckBox
    Private CheckBox4 As CheckBox
    Private CheckBox5 As CheckBox
    Public boxes As Map
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    boxes.Initialize
    boxes.Put("A",CheckBox1)
    boxes.Put("B",CheckBox2)
    boxes.Put("C",CheckBox3)
    boxes.Put("D",CheckBox4)
    boxes.Put("E",CheckBox5)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub CheckBox_CheckedChange(Checked As Boolean)
    Dim chk As CheckBox = Sender
    If Checked Then
        For Each box As CheckBox In boxes.Values
            If box <> chk Then
                box.Checked = False
            End If
        Next
    End If
End Sub
 

Attachments

Last edited:
Top