java - 只有一个单选按钮

标签 java android

我在一个示例中读到,如果您使用多个单选按钮,则应该使用 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.

但是,与复选框相反,单选按钮 一旦选中,用户就无法取消选中。

因此,如果您只想提供一个选项按钮来选择用户,请使用 CheckBoxToggleButton

关于java - 只有一个单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949963/

相关文章:

java - 我应该从 Applets 迁移出去吗?如果是,迁移到什么地方?

java - 访问列表的值

java - java中如何在没有打印对话框的情况下进行打印

android - Android 单声道 : Which Testing Frameworks work

android - 如何在 Android 中停止 Firebase 事件监听器?

java - 数学解析器 - 标记结构

java - 错误 StatusLogger Log4j2 找不到日志记录实现

java - 如何保持微调器中选定的项目处于选中状态,直到用户选择不同的项目..?

java - onActivityResult 方法没有被调用

c# - Xamarin Android 和 Azure SQL