Monday 18 February 2013

Getting Selected Radio Button Value from Radio Group in Android

// Gets a reference to our radio group
// rBtnDigits is the name of our radio group (code not shown)
RadioGroup g = (RadioGroup) findViewById(R.id.rBtnDigits);

// Returns an integer which represents the selected radio button's ID
int selected = g.getCheckedRadioButtonId();

// Gets a reference to our "selected" radio button
RadioButton b = (RadioButton) findViewById(selected);

// Now you can get the text or whatever you want from the "selected" radio button
b.getText();

No comments:

Post a Comment