2015-12-23 17 views
0

我有一個內置動態選項的抽屜菜單,我需要填充它。 我想清除adapter內部的RadioGroup的所有孩子,但我沒有找到任何東西。清除一個視圖的所有孩子(RadioGroup)

P.S:我填補所有RadioGroupaddViewCheckBox

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); 
} 
+0

radioGroup.clearCheck(); –

+0

@DhawalSodhaParmar我想清除孩子,不清除檢查 – Ashkan

回答

2

嘗試:

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); 
      } 
     } 
    } 
+0

@Ashkan如果你想刪除所有視圖,然後刪除**如果(o instanceof RadioButton)**線從代碼 – Joker

+0

nope,該項目是比這更多。而且我現在還沒有做到這一點。 – Ashkan

+0

我無法理解你。你想要做的究竟是什麼。請重新編輯question.to更清楚 – Joker

0

這從鏈路here採取複雜的嵌套佈局

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); 
     } 
    } 
} 
相關問題