Get text (String) from a RadioButton within a RadioGroup


I want to get the text of rabiobutton selected by the user. I have 5 radiobutton within a radiogroup to then use this field in an Asynctask and insert in a BD. the fact is that I can not get the text.

What I have is the following

        radioGroup=(RadioGroup) findViewById(;
        rbmuybueno=(RadioButton) findViewById(;
        rbbueno=(RadioButton) findViewById(;
        rbregular=(RadioButton) findViewById(;
        rbmalo=(RadioButton) findViewById(;
public void  validarradiobutton(){
    if (rbmuybueno.isChecked() || rbbueno.isChecked() || rbmalo.isChecked() || rbregular.isChecked()  || rbmuymalo.isChecked())

            final String pregunta=preguntaa.getText().toString();

        final AlertDialog.Builder alertaDeError2 = new AlertDialog.Builder(CalificarEvento.this);
        alertaDeError2.setMessage("Selecione una alternativa para continuar.");
        alertaDeError2.setPositiveButton("Entendido", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {


I need to get the text inside the IF and then pass the parameters to the Asynctask

asked by Ashley G. 11.01.2017 в 21:33

1 answer


If you have a RadioButton to get the text it would be:

 rbmuybueno=(RadioButton) findViewById(;
 String texto = rbmuybueno.getText().toString();

If you have a RadioGroup containing RadioButtons , you would first get the id of RadioGroup :

int radioButtonId = radioButtonGroup.getCheckedRadioButtonId();

You would get a reference of the element by means of the id:

View radioButton = radioButtonGroup.findViewById(radioButtonId);

and you would get the index of RadioButton within RadioGroup :

int indice = radioButtonGroup.indexOfChild(radioButton);

To get the RadioButton text:

 RadioButton rb = (RadioButton)  radioButton.getChildAt(indice);
 String texto = rb.getText().toString();
answered by 11.01.2017 / 22:03