Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radio Button does not toggle its state

Tags:

android

I add a RadioButton in my layout.

It is unchecked to begin with. And when I click on it , it becomes checked (as shown in emulator). But when when i click on it again, it does not become unchecked again?

<RadioButton android:checked="false"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:id="@+id/option1"/>
like image 388
michael Avatar asked Jul 26 '10 19:07

michael


1 Answers

If you're looking for checkbox behavior with radio button appearance, you could pass in the xml style to a checkbox.

<CheckBox android:checked="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/option1"
         style="@android:style/Widget.DeviceDefault.Light.CompoundButton.RadioButton/>

This can be useful in some cases (ex. using radio buttons in a RecyclerView) but you should be careful because the user expects radio buttons to behave a certain way. If you're allowing the user to make multiple selections you should probably use a normal checkbox, as mentioned in the comments above.

Hope this helps!

like image 128
Christoferson Avatar answered Sep 20 '22 03:09

Christoferson