Android get value of the selected radio button

自闭症网瘾萝莉.ら 提交于 2019-11-27 13:55:53

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();
}
ρяσѕρєя K

try this:

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

One Line Code

String buisnesstype = ((RadioButton) rdtranscompany.findViewById(rdtranscompany.getCheckedRadioButtonId())).getText().toString();
karthik gorijavolu
rb1=(RadioButton)findViewById(rg1.getCheckedRadioButtonId());

Now you can use rb1.getText() to get the text on the Radiobutton that is checked

Faruk Nasir

I think you should try this

RadioGroup rg=(RadioGroup)findViewById(R.id.youradio);
String radiovalue=(RadioButton)this.findViewById(rg.getCheckedRadioButtonId())).getText().toString();
RadioGroup bhktype_RadioGr = (RadioGroup)findViewById(R.id.bhkypeRadioGroup);
int flatTypeId = bhktype_RadioGroup.getCheckedRadioButtonId();
String flat_type = ((RadioButton) findViewById(flatTypeId)).getText().toString();
vincent

SImple answer one line

View v = yourView;  // as a button

String radiovalue = (RadioButton)v).getText().toString();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!