tags:

views:

70

answers:

3

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"/>
A: 

That is a conceptual question: Radio buttons allow you to choose between several options (represented by the other radio buttons). Typically, one radio button out of a group is always checked, even if in an initial state no buttons may be checked if you do not declare one as a default value. That means also that a single button does not allow to toggle its state unless other radio buttons are present in the same group - if there is only one option, you will have to choose it.

If you want a binary toggle, you will want to use a checkbox instead.

relet
+1  A: 

If you are only using one radio box for checking on and off, maybe you should use checkbox or toggle button instead.

http://developer.android.com/resources/tutorials/views/hello-formstuff.html

Scroll down and see checkbox and toggle button.

When using radios you usually have more than one and choose between them. Like easy, medium, hard.

Cameron
how can I specify 'android's checkboxStyle' in my of my own control?
michael
+2  A: 

If you are having more than 1 radio buttons to work with then add "RadioGroups" as follows:

<RadioGroup android:id="@+id/group1" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:orientation="vertical">
        <RadioButton android:id="@+id/radio1" android:text="madras"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
        <RadioButton android:id="@+id/radio2" android:text="bombay"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </RadioGroup>

Have a look at this example , i am sure this will make your idea clear regarding Radio Buttons.

Also refer this Android Developer - Form Stuff page .

PM - Paresh Mayani