1

I have a drawer menu with a dynamic option inside it and I got to fill it. I want to clear all the child of a RadioGroup inside adapter but I didn't find anything.

p.s: I fill all RadioGroup with addView and fill it with CheckBox

ps2: The question is not about the check and uncheck. I want to find out how can remove all child of a view (like RadioGroup).

viewHolder.mRadioGroup.setVisibility(View.VISIBLE);
/////clear viewHolder.mRadioGroup child hear, befor add new child to it
for (int i; i<10; i++) {
   RadioButton radioButton = new RadioButton(mContext);
   radioButton.setText(selectableValue.getValue());
   viewHolder.mRadioGroup.addView(radioButton);
}
Ashkan
  • 1,357
  • 4
  • 16
  • 37

2 Answers2

4

Try This :

    int count = radioGroup.getChildCount();
    if(count>0) {
       for (int i=count-1;i>=0;i--) {
           View o = radioGroup.getChildAt(i);
           if (o instanceof RadioButton) {
               radioGroup.removeViewAt(i);
           } 
       } 
    }
Ashkan
  • 1,357
  • 4
  • 16
  • 37
Joker
  • 537
  • 1
  • 6
  • 19
0

This taken from link here for complex nested layout

private static void disable(ViewGroup layout) {
    layout.setEnabled(false);
    for (int i = 0; i < layout.getChildCount(); i++) {
        View child = layout.getChildAt(i);
        if (child instanceof ViewGroup) {
            disable((ViewGroup) child);
        } else { 
            child.setEnabled(false);
        } 
    } 
} 
Community
  • 1
  • 1
Joker
  • 537
  • 1
  • 6
  • 19