Android get value of the selected radio button

前端 未结 8 978
慢半拍i
慢半拍i 2020-12-03 06:53

I have a RadioGroup rg1 and I want to get the value of the selected radio button.

I know that I can get the id of the selected radio button

相关标签:
8条回答
  • 2020-12-03 07:28
    RadioGroup rg = (RadioGroup)findViewById(R.id.youradio);
    String radiovalue = (RadioButton)this.findViewById(rg.getCheckedRadioButtonId())).getText().toString();  
    
    0 讨论(0)
  • 2020-12-03 07:30

    SImple answer one line

    View v = yourView;  // as a button
    
    String radiovalue = (RadioButton)v).getText().toString();
    
    0 讨论(0)
  • 2020-12-03 07:33

    One Line Code

    String buisnesstype = ((RadioButton) rdtranscompany.findViewById(rdtranscompany.getCheckedRadioButtonId())).getText().toString();
    
    0 讨论(0)
  • 2020-12-03 07:35

    I think you should try this

    RadioGroup rg=(RadioGroup)findViewById(R.id.youradio);
    String radiovalue=(RadioButton)this.findViewById(rg.getCheckedRadioButtonId())).getText().toString();
    
    0 讨论(0)
  • 2020-12-03 07:37
    rb1=(RadioButton)findViewById(rg1.getCheckedRadioButtonId());
    

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

    0 讨论(0)
  • 2020-12-03 07:45
    RadioGroup bhktype_RadioGr = (RadioGroup)findViewById(R.id.bhkypeRadioGroup);
    int flatTypeId = bhktype_RadioGroup.getCheckedRadioButtonId();
    String flat_type = ((RadioButton) findViewById(flatTypeId)).getText().toString();
    
    0 讨论(0)
提交回复
热议问题