如何获取动态创建的单选按钮的文本?

时间:2011-08-24 15:19:25

标签: android radio-button

您好我创建了一个radioGroup并动态添加了radiobuttons ......

Radiogroup= (RadioGroup) findViewById(R.id.Radiogroup);

    for (int i=0; i<3 i++){
      Radiob = new RadioButton(Radiogroup.this);
                         Radiob.setText("whatever");
                         Radiob.setId(i);
                         Radiogroup.addView(Radiob);
    }

问题是如何才能获得这些Radiobutton的文本?

1 个答案:

答案 0 :(得分:0)

String[] textRadios = new String[3];

 for (int i=0; i<3 i++){
      Radiob = new RadioButton(Radiogroup.this);
      textRadios[i]=Radiob.getText().toString();
      Log.i("RadioButton: "+i, textRadios[i]);
    }