首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >只有一个单选按钮

只有一个单选按钮
EN

Stack Overflow用户
提问于 2012-10-18 16:10:02
回答 2查看 222关注 0票数 0

我在一个例子中读到,如果你使用多个单选按钮,你应该像这样使用RadioGroup

代码语言:javascript
运行
复制
<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>吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-18 16:17:53

doc

单选按钮是两种状态的按钮,既可以选中,也可以取消选中。取消选中该单选按钮时,用户可以按下或单击该按钮以选中它。然而,与CheckBox相反,单选按钮一旦被选中,用户就不能取消选中。

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

因此,如果您只希望提供一个选项按钮来选择用户,那么可以使用CheckBoxToggleButton

票数 2
EN

Stack Overflow用户

发布于 2012-10-18 16:17:40

是的你可以。

但是如果有一个单选按钮,那么一旦你选中它,你就可以取消选中它,因为。

代码语言:javascript
运行
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12949963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档