How to get radio button's id and convert to string?
Posted
by
user3461659
on Stack Overflow
See other posts from Stack Overflow
or by user3461659
Published on 2014-05-30T02:59:35Z
Indexed on
2014/05/30
3:26 UTC
Read the original article
Hit count: 104
I am working in Android Studio and am trying to get the ID of the selected radio button and then store the ID in a string. Is this possible?
I have tried replacing the .getText() method below with .getId() but it wont let me store it as a string:
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId)
{
RadioButton checkedRadioButton = (RadioButton) findViewById(checkedId);
String text = checkedRadioButton.getText().toString();
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
}
});
© Stack Overflow or respective owner