Android get value of the selected radio button Android get value of the selected radio button android android

Android get value of the selected radio button


You need to get the radio button at that index, then get the value of the text of that button. Try this code below.

if(rg1.getCheckedRadioButtonId()!=-1){    int id= rg1.getCheckedRadioButtonId();    View radioButton = rg1.findViewById(id);    int radioId = radioGroup.indexOfChild(radioButton);    RadioButton btn = (RadioButton) rg1.getChildAt(radioId);    String selection = (String) btn.getText();}


try this:

RadioGroup rg = (RadioGroup)findViewById(R.id.youradio);String radiovalue = ((RadioButton)findViewById(rg.getCheckedRadioButtonId())).getText().toString();  


RadioGroup rg = (RadioGroup)findViewById(R.id.youradio);String radiovalue = (RadioButton)this.findViewById(rg.getCheckedRadioButtonId())).getText().toString();