I want to get the text of the rabiobutton
selected by the user. I have 5 radiobutton
inside a radiogroup
to then use this field in an Asynctask and insert it into a DB. The thing is, I can't get the text.
What I have is the following
radioGroup=(RadioGroup) findViewById(R.id.radiog1);
rbmuybueno=(RadioButton) findViewById(R.id.rbmuybien);
rbbueno=(RadioButton) findViewById(R.id.rbbueno);
rbregular=(RadioButton) findViewById(R.id.rbregular);
rbmalo=(RadioButton) findViewById(R.id.rbmala);
rbmuymalo=(RadioButton)findViewById(R.id.rbmuymala);
public void validarradiobutton(){
if (rbmuybueno.isChecked() || rbbueno.isChecked() || rbmalo.isChecked() || rbregular.isChecked() || rbmuymalo.isChecked())
{
final String pregunta=preguntaa.getText().toString();
}
else
{
final AlertDialog.Builder alertaDeError2 = new AlertDialog.Builder(CalificarEvento.this);
alertaDeError2.setTitle("Advertencia");
alertaDeError2.setMessage("Selecione una alternativa para continuar.");
alertaDeError2.setPositiveButton("Entendido", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertaDeError2.create();
alertaDeError2.show();
}
I need to get the text inside the IF to then pass the parameters to the Asynctask
If you have a
RadioButton
to get the text it would be:If you have a
RadioGroup
containingRadioButtons
, you would first get the id of theRadioGroup
:you would get a reference of the element by means of the id:
and you would get the index of the
RadioButton
inside of theRadioGroup
:To get the text of the RadioButton: