sara
sara

Reputation: 81

only one radio buttons

I have read in an example that if you use more than one radio button you should use RadioGroup like this:

<RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


       <RadioButton
           android:id="@+id/radio_pirates"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginTop="14dp"
           android:layout_marginLeft="100dp"
           android:onClick="onRadioButtonClicked"
           android:text="@string/attendance"
           android:textSize="8dp"

            />
   <RadioButton
           android:id="@+id/radio_pirates2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginTop="14dp"
           android:layout_marginLeft="100dp"
           android:onClick="onRadioButtonClicked"
           android:text="@string/attendance"
           android:textSize="8dp"

            />
       </RadioGroup>

If I have only one radio button, can I remove <RadioGroup> or that is wrong ?

Upvotes: 0

Views: 252

Answers (1)

subodh
subodh

Reputation: 6158

From the doc

A radio button is a two-states button that can be either checked or unchecked. When the radio button is unchecked, the user can press or click it to check it. However, contrary to a CheckBox, a radio button cannot be unchecked by the user once checked.

However, contrary to a CheckBox, a radio button cannot be unchecked by the user once checked.

So, if you wish to give only one option button to select the user then use CheckBox or ToggleButton

Upvotes: 2

Related Questions