RadioGrouprg1
があり、選択したラジオ ボタンの値を取得したいと考えています。
id
次を使用して、選択したラジオボタンの を取得できることを知っています。
if(rg1.getCheckedRadioButtonId()!=-1)
int id= rg1.getCheckedRadioButtonId()
それは私に id を与えますが、そのボタンの値が欲しいです。
RadioGrouprg1
があり、選択したラジオ ボタンの値を取得したいと考えています。
id
次を使用して、選択したラジオボタンの を取得できることを知っています。
if(rg1.getCheckedRadioButtonId()!=-1)
int id= rg1.getCheckedRadioButtonId()
それは私に id を与えますが、そのボタンの値が欲しいです。
そのインデックスでラジオ ボタンを取得し、そのボタンのテキストの値を取得する必要があります。以下のコードを試してください。
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();
}
これを試して:
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();
1 行コード
String buisnesstype = ((RadioButton) rdtranscompany.findViewById(rdtranscompany.getCheckedRadioButtonId())).getText().toString();
私はあなたがこれを試してみるべきだと思います
RadioGroup rg=(RadioGroup)findViewById(R.id.youradio);
String radiovalue=(RadioButton)this.findViewById(rg.getCheckedRadioButtonId())).getText().toString();