Android RadioButton allow more than one to be chec

2020-05-02 13:18发布

问题:

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-radiobuttons-to-be-selected

How can I purposefully allow 3 radiobutton to be selected at a time and implement a listener for those three selected.

I suspect I am doing something wrong. Is there another UI element out there that can help me get what I am looking for?

回答1:

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.

If you really need to do this, you either need to use multiple RadioGroup objects, or use checkboxes instead.

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)