Friday 15 February 2013

Validate or Check if RadioGroup RadioButtons are not Checked ?

RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup);
int radioButtonId = rg.getCheckedRadioButtonId();

                        if (radioButtonId == -1) {
                              Toast.makeText(getApplicationContext(),
                                          "Please select atleast one option", 3000).show();
                        }

                        else {
          RadioButton radioButton = (RadioButton) findViewById(radioButtonId);
                              String radioValue = radioButton.getText().toString();
                              Toast.makeText(getApplicationContext(), radioValue, 3000)
                                          .show();
                        }

No comments:

Post a Comment