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

本文标题为:Android RadioButton 允许检查多个

基础教程推荐