Радио-группа Android - PullRequest
       0

Радио-группа Android

2 голосов
/ 22 июня 2011

Я создаю 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 голосов
/ 16 июля 2012
int selectedRadioId = rg2.getCheckedRadioButtonId();
RadioButton selectedRadioButton = rg2.findViewById(selectedRadioId);
String selectedText = selectedRadioButton.getText(); // "Veg" or "Non-veg"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...