This question already has answers here:
Uncheck all RadioButton in a RadioButtonGroup
(3个答案)
4年前关闭。
我有一个带有动态选项的抽屉菜单,我必须填写它。
我想清除
ps:我将所有
ps2:问题不在于检查和取消检查。我想了解如何删除视图的所有子对象(如
(3个答案)
4年前关闭。
我有一个带有动态选项的抽屉菜单,我必须填写它。
我想清除
RadioGroup
中所有adapter
的子级,但是我什么也没找到。ps:我将所有
RadioGroup
填充为addView
,然后将其填充为CheckBox
ps2:问题不在于检查和取消检查。我想了解如何删除视图的所有子对象(如
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);
}
最佳答案
尝试这个 :
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);
}
}
}