Android广播组

时间:2011-06-22 09:44:24

标签: android radio-button

我在RadioGroup内创建radio button如何将radio button中的选定值存储到数组列表中?

TableLayout ch = (TableLayout) findViewById(R.id.tablechild);
TableRow row2 = new TableRow(Edittextsample.this);
TextView m = new TextView(Edittextsample.this);
m.setText("Meals");
RadioGroup rg2 = new RadioGroup(Edittextsample.this);
rg2.setOrientation(TableLayout.HORIZONTAL);
RadioButton r = new RadioButton(Edittextsample.this)
r.setText("Veg");
r.setTextSize(12);
rg2.addView(r);

RadioButton r1 = new RadioButton(Edittextsample.this)
r1.setText("Non-Veg");
 r1.setTextSize(12);
rg2.addView(r); 
ch.addView(row2,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,    LayoutParams.WRAP_CONTENT));

1 个答案:

答案 0 :(得分:0)

int selectedRadioId = rg2.getCheckedRadioButtonId();
RadioButton selectedRadioButton = rg2.findViewById(selectedRadioId);
String selectedText = selectedRadioButton.getText(); // "Veg" or "Non-veg"