Android RadioButton allow more than one to be check(Android RadioButton 允许检查多个)
问题描述
我有一个带有大约 30 个单选按钮的单选按钮组.我在stackoverflow上环顾四周,发现了一些关于意外允许检查多个单选按钮的帖子.他们不在广播组中,或者他们的 id 有问题.
I have a radiogroup with about 30 radiobuttons. I have looked around on stackoverflow and found a few posts about the accidental allowing of multiple radiobuttons to be checked. They were not in a radiogroup, or had problems with their id.
https://stackoverflow.com/questions/8265034/android-radiogroup-checks-more-than-one-radiobuttonhttps://stackoverflow.com/questions/17157705/radiogroup-allows-multiple-待选择的单选按钮
我怎样才能有目的地允许一次选择 3 个单选按钮并为这三个选择一个监听器.
How can I purposefully allow 3 radiobutton to be selected at a time and implement a listener for those three selected.
我怀疑我做错了什么.是否还有其他 UI 元素可以帮助我获得所需的内容?
I suspect I am doing something wrong. Is there another UI element out there that can help me get what I am looking for?
推荐答案
RadioGroups 设计为仅允许 1 个选择.用户在使用 RadioGroup 时具有基本上类似于复选框的行为会让人感到困惑.
RadioGroups are designed to only allow 1 selection. It's confusing for users to have what is basically checkbox-like behaviour when they are using a RadioGroup.
如果你真的需要这样做,你要么需要使用多个 RadioGroup 对象,要么使用复选框.
If you really need to do this, you either need to use multiple RadioGroup objects, or use checkboxes instead.
Android Checkbox 文档在这里:http://developer.android.com/参考/android/widget/CheckBox.html
Android Checkbox documentation is here: http://developer.android.com/reference/android/widget/CheckBox.html
您可以使用以下方法将侦听器附加到复选框对象:
You can attach listeners to the checkbox objects by using the following:
public void setOnCheckedChangeListener (CompoundButton.OnCheckedChangeListener listener)
这篇关于Android RadioButton 允许检查多个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android RadioButton 允许检查多个
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01