2013-11-23 46 views
0

我動態地創建了n個radiogroup,每個radiogroup都有k個radiobutton。 我想將選中的單選按鈕文本保存到文件中,但我不知道如何獲取每個radiogroup檢查的單選按鈕ID。如何獲得很多RadioGroup檢查過的單選按鈕?

我創建單選按鈕,並RadioGroup中是這樣的:

if (Integer.parseInt(cells[1])==1){ 
       rg = new RadioGroup(this); 
       for (int i=2;i<cells.length;i++){ 
        rb = new RadioButton(this); 
        rb.setText(cells[i]); 
        rb.setId(i); 
        rg.addView(rb); 

       } 
       lin.addView(rg); 

      } 

請幫幫我!

回答

0

迭代所有的環路的RadioGroup中的

for (int i = 0; i < particularRadioGroup.getChildCount(); i++) { 
    RadioButton childAt = (RadioButton) particularRadioGroup.getChildAt(i); 
    boolean checked = childAt.isChecked(); 
    int id = childAt.getId(); 
    String text = childAt.getText().toString(); 
    // Save the Data of the RadioButton of the Particluar RadioGroup 
    // Save Here 
}