0

I have 16 Radio Group in my layout and i have 40 Radio Button . I want to get which Radio Button is unchecked in Radio Groups. I want to know how can i know is there any unchecked Radio Button in my layout thanks

3 Answers3

1

You should probably group all of your buttons like so:

RadioGroup rg = (RadioGroup) findViewById(R.id.my_radio_group);
List<RadioButton> radioButtonsList = new ArrayList<>();
for(int i = 0; i < rg.getChildCount(); ++i) {
   RadioButton b = rg.getChildAt(i);
   if(b.isChecked()) radioButtonsList.add(b);
}

Do it for all of your groups and you'll have all your unchecked buttons in a list.

Also you can use:

int checkedRadioButtonId = rg.getCheckedRadioButtonId()

to get only checked button's id.

shadox
  • 3,238
  • 4
  • 24
  • 38
0

You can check the state of radio buttons by using the isChecked() method.

This question has already been answered here:

How to check if "Radiobutton" is checked?

Community
  • 1
  • 1
Will Evers
  • 934
  • 9
  • 17
0
    ArrayList<RadioGroup> radioGroupList = new ArrayList<RadioGroup>();
    RadioGroup group1 = (RadioGroup)findViewById(...);
    RadioGroup group2 = (RadioGroup)findViewById(...);
    .
    .
    RadioGroup group16 = (RadioGroup)findViewById(...);
    radioGroupList.add(group1);
    radioGroupList.add(group2);
    .
    .
    radioGroupList.add(group16);

and later you can check which is checked or not with this

    for(RadioGroup radioButtonGroup:RadioGroupList){
        int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
        View radioButton = radioButtonGroup.findViewById(radioButtonID);
        int idx = radioButtonGroup.indexOfChild(radioButton);
    }

or if it's the RadioButtons you are interested in then add them in an ArrayList the same way and loop in that list like this

for(RadioButton radioButton:radioButtonList){
    boolean isChecked = radioButton.isChecked();
}
Anonymous
  • 4,470
  • 3
  • 36
  • 67