Android UI How to - RadioGroup with More Than Just RadioButtons








You can have non-RadioButton controls inside a radio group.

Example

The following RadioGroup adds a TextView after the last radio button. Also note that the first radio button (anotherRadBtn) lies outside the radio group.

//from ww w . j  a v a2  s.c  om
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <RadioButton
        android:id="@+id/anotherRadBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Outside" />

    <RadioGroup
        android:id="@+id/radGrp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/chRBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Chicken" />

        <RadioButton
            android:id="@+id/fishRBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Fish" />

        <RadioButton
            android:id="@+id/stkRBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Steak" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My Favorite" />

    </RadioGroup>
</LinearLayout>
null




Note

The radio group can only enforce single-selection on the radio buttons in its own container.