Android Question Checkbox syntax

Discussion in 'Android Questions' started by Yves Mazzon, May 3, 2015.

  1. Yves Mazzon

    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
     
  2. DonManfred

    DonManfred Expert Licensed User

    Code:
    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
     

    Attached Files:

    mark35at and Yves Mazzon like this.
  3. klaus

    klaus Expert Licensed User

    Why do you want to use CheckBoxes for that.
    You could use RadioButtons instead.
     
    Yves Mazzon likes this.
  4. Yves Mazzon

    Yves Mazzon Member Licensed User

    Many thanks DonManfred, it works for me.
    Regards,

    Yves
     
  5. RVP

    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.
     
  6. Yves Mazzon

    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
     
  7. klaus

    klaus Expert Licensed User

    That's what RadioButtons are made for !
    Only one button can be selected at once.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice