Android的单选按钮允许多个要检查多个、单选、按钮、Android

2023-09-04 03:30:29 作者:风吹裤裆毛飞扬≈

我有一个 RadioGroup中约30单选按钮。我环顾四周的计算器,发现被检查有关意外允许多个单选按钮的几个职位。他们的不是一个RadioGroup中,或有问题与他们的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.

http://stackoverflow.com/questions/8265034/android-radiogroup-checks-more-than-one-radiobuttonhttp://stackoverflow.com/questions/17157705/radiogroup-allows-multiple-radiobuttons-to-be-selected

我怎么能故意让 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的复选框的文档是在这里: http://developer.android.com/参考/安卓/空间/ 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)