Multiple RadioButton can be selected in a RadioGroup android

android, dynamic, radio-button, view

Solution

I recreated your problem and solved it by giving each RadioButton a unique id, something simple like:

rb.setId(list_answers.get(j).getQuizz_answers_id() + i * list_questions.size());

I'm not sure why the default OnCheckedChangeListeners are getting confused at this moment, but here's an easy fix.

Problem

I'm adding programatically (obliged as the number of radiogroup and radiobuttons are variables) radiogroups in my activity layout like that : ``` rg = new RadioGroup(this); rg.setOrientation(RadioGroup.HORIZONTAL); rg.setId(list_questions.get(i).getQuizz_questions_id()); // get from the DB lrg.add(rg); for (int j = 0; j < list_answers.size(); j++) { rb = new RadioButton(this); rb.setId(list_answers.get(j).getQuizz_answers_id()); rb.setText(String.valueOf(list_answers.get(j).getQuizz_answers_id()) + "-" + String.valueOf(list_answers.size()) + "-" + String.valueOf(list_questions.get(i).getQuizz_questions_id())); // I added that to see if there was a problem on the indexes, but there's not rg.addView(rb, new LayoutParams(100,LayoutParams.WRAP_CONTENT)); } tr.addView(rg, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); ``` Complete code can be found here : http://pastebin.com/d9zZjmuu My problem is that I can select two radiobuttons inside three radiogroup. I know that it'll be difficult for you to help as you don't have all the sources etc. but I am searching what's the problem since two days and didn't find anything so if you can just tell me if you have any idea of where the problem can come from it will be really appreciated ! Thanks and sorry for my bad english.

Original source