Android Question Check only one checkbox

Discussion in 'Android Questions' started by Kiran Raotole, Jun 1, 2019.

  1. Kiran Raotole

    Kiran Raotole Active Member Licensed User

    I want to uncheck all another checkbox of that same event, when new check box checked.
     
  2. LucaMs

    LucaMs Expert Licensed User

    Radiobuttons on a panel to do that.
     
  3. DonManfred

    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.

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

    Attached Files:

    Last edited: Jun 1, 2019
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