我在一个示例中读到,如果您使用多个单选按钮,则应该使用 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>
或者这是错误的?
最佳答案
来自doc
A radio button is a two-states button that can be either checked or unchecked. When the radio button is unchecked, the user can press or click it to check it. However, contrary to a CheckBox, a radio button cannot be unchecked by the user once checked.
但是,与复选框相反,单选按钮 一旦选中,用户就无法取消选中。
因此,如果您只想提供一个选项按钮来选择用户,请使用 CheckBox
或 ToggleButton
关于java - 只有一个单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949963/