ででりんブログ

写真やプログラミングを中心とした雑記帳

スポンサーリンク

【Android】ラジオグループ

スポンサーリンク

ラジオボタンを複数配置してもそれぞれ独立した選択となってしまいます。

f:id:dederin-photo:20160721231307p:plain,h500

これをグループ扱いとしていずれか1つしか選択できないようにする方法のメモ。

f:id:dederin-photo:20160721231311p:plain,h500

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New RadioButton"
            android:id="@+id/radioButton"
            android:checked="false" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New RadioButton"
            android:id="@+id/radioButton2"
            android:checked="false" />
    </RadioGroup>

結論としてはラジオボタンコンポーネントをラジオグループのコンポーネントで囲むだけです。

スポンサーリンク