Android Question Checkbox syntax

Yves Mazzon

Member
Licensed User
Hello all,
I need help to understand the checkbox syntax. I have two checkboxes called check1 and check2. What I wanted to do is when I check check1, check2 uncheck and vice versa. In the same time it will disable or unable some label entries. Many thanks in advance.
Regards,
Yves
 

DonManfred

Expert
Licensed User
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 chk1 As CheckBox
    Private chk2 As CheckBox
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")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub chkBox_CheckedChange(Checked As Boolean)
    Dim chk As CheckBox = Sender
    Log("Tag = "&chk.Tag&": "&Checked)
    If Checked Then
        If chk.Tag = "Check1" Then
            chk2.Checked = False
        End If
        If chk.Tag = "Check2" Then
            chk1.Checked = False
        End If
    Else
        If chk.Tag = "Check1" Then
            chk2.Checked = True
        End If
        If chk.Tag = "Check2" Then
            chk1.Checked = True
        End If
   
    End If
End Sub
 

Attachments

RVP

Active Member
Licensed User
I have to agree with Klaus, you should use the correct interface element for the task. Radio buttons are understood to be one of a selection, checkboxes are for when you can select any or all. User interfaces should be consistent for the platform you are developing on and follow its guidelines. Otherwise you will confuse the user by an un expected behaviour.
 

Yves Mazzon

Member
Licensed User
If I understood the radio buttons will automatically turn off when another one is pressed like the old radio system and two radio buttons can never be on at the same time. I agree it is a better idea and will take a lot of overhead code I had to use with the checkboxes.
Regards,
Yves
 

klaus

Expert
Licensed User
If I understood the radio buttons will automatically turn off when another one is pressed like the old radio system and two radio buttons can never be on at the same time.
That's what RadioButtons are made for !
Only one button can be selected at once.
 
Top