一個單選按鈕給用戶幾個選擇和用戶只能選擇一個項目。
單選按鈕通常屬于一個組,并且每個組只能有一次選擇一個項目。
要在Android中創(chuàng)建一組單選按鈕,首先創(chuàng)建一個 RadioGroup
,然后使用單選按鈕填充組。
在Android中,您使用 android.widget.RadioGroup
實現(xiàn)一個單選組和無線電按鈕使用 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>
更多建議: