Android RadioButton 允许检查多个

Android RadioButton allow more than one to be check(Android RadioButton 允许检查多个)
本文介绍了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 允许检查多个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)