A radio button gives the users several choices and users can only selec a single item.
Radio buttons generally belong to a group, and each group can only have one item selected at a time.
To create a group of radio buttons in Android, first create a RadioGroup
, and then
populate the group with radio buttons.
In Android, you implement a radio group using android.widget.RadioGroup
and a radio
button using android.widget.RadioButton
.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <RadioGroup android:id="@+id/rBtnGrp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <RadioButton android:id="@+id/chRBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="XML" /> <RadioButton android:id="@+id/fishRBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="HTML" /> <RadioButton android:id="@+id/stkRBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CSS" /> </RadioGroup> </LinearLayout>