0

I add a Radio Button in my layout.

It is unchecked to begin with. And when I click on it , it becomes checked. But when i click on it again, it does not become unchecked again?

1 Answers1

0

RadioButton doesn't go from checked-state to unchecked-state on clicking. There is a simple solution for this. For your requirement, I would rather suggest you to use ToggleButton.

i) Add the below xml and 2 drawables(checked and unchecked) to your drawable-folder.

toggle_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item   android:state_checked="true"
            android:drawable="@drawable/checked" /> <!-- checked -->
    <item   android:state_checked="false"
            android:drawable="@drawable/unchecked" /> <!-- unchecked -->
</selector>

ii) Replace your RadioButton with ToggleButton.

iii) Set the background of your toggleButton to above xml-drawable.

Hope this helps.

Gagan
  • 1,497
  • 1
  • 12
  • 27