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