The Radio button, if checked, must be unchecked.

I have a group of radio stations in my project, how to uncheck all the checkboxes before starting and how to uncheck the box if another checkbox is selected. When I clicked on another button, he did not uncheck the other, and I can’t figure out how to deal with it. I can’t even get the index of these buttons, I mean, I can get the value of the text field. I got the code on but, unfortunately, it clearly does not explain its code.

code

<RadioGroup
   android:id="@+id/radioGender"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" >
         
   <RadioButton
      android:id="@+id/genderMale"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Male"
      android:checked="true" />

   <RadioButton
      android:id="@+id/genderFemale"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Female" />
        
</RadioGroup>
+3
source share
3 answers

Add radio objects to a radio group

<RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:orientation="horizontal"
        >

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="true"
            android:text="One" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Two" />

</RadioGroup>
+4
source

To unmark all switches:

RadioButtonGroup rgButton = (RadioButtonGroup)findViewById(R.id.radiobuttongroup);
rgButton.clearCheck();

if the radio buttons are in the same radio group, therefore automatically, when you check one, the other will be removed.

, :

if(rb.isChecked()==true)
+3

I came across this question while looking for another problem, but good to share knowledge, I faced the same problem, anyone who encounters this problem, do not forget to add @ + id for each RadioButton ninja good luck.

+1
source

All Articles