Android RadioButton allow more than one to be check

五迷三道 提交于 2019-12-02 16:29:52

问题


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)


来源:https://stackoverflow.com/questions/19306849/android-radiobutton-allow-more-than-one-to-be-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!