我在一个例子中读到,如果你使用多个单选按钮,你应该像这样使用RadioGroup
:
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radio_pirates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_marginLeft="100dp"
android:onClick="onRadioButtonClicked"
android:text="@string/attendance"
android:textSize="8dp"
/>
<RadioButton
android:id="@+id/radio_pirates2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_marginLeft="100dp"
android:onClick="onRadioButtonClicked"
android:text="@string/attendance"
android:textSize="8dp"
/>
</RadioGroup>
如果我只有一个单选按钮,我可以删除<RadioGroup>
吗?
发布于 2012-10-18 16:17:53
从doc
单选按钮是两种状态的按钮,既可以选中,也可以取消选中。取消选中该单选按钮时,用户可以按下或单击该按钮以选中它。然而,与CheckBox相反,单选按钮一旦被选中,用户就不能取消选中。
但是,与CheckBox相反,单选按钮一旦被选中,用户就无法取消选中。
因此,如果您只希望提供一个选项按钮来选择用户,那么可以使用CheckBox
或ToggleButton
发布于 2012-10-18 16:17:40
是的你可以。
但是如果有一个单选按钮,那么一旦你选中它,你就可以取消选中它,因为。
Intially, all of the radio buttons are unchecked.While it is not possible to
uncheck a particular radio button, the radio group can be cleared to remove the
checked state.
所以最好使用Check Box
而不是单选按钮。Example
https://stackoverflow.com/questions/12949963
复制相似问题