I was wondering how to setError
for a RadioGroup
[gender] with RadioButton
's [gender_b,gender_c] if it is null.
This is how i'm getting the RadioButton
values though:
private boolean genradiocheck() {
boolean gender_flag = false;
if (gender.getCheckedRadioButtonId() == -1) {
} else {
gender_b = (RadioButton) findViewById(gender
.getCheckedRadioButtonId());
System.out.println("*********************" + gender_b.getText());
gender_flag = true;
}
return gender_flag;
}
Now my question is, how do i put it into a string and check for null values?
This is for a Registration form validation. Thank you.
setError()
method is not available for RadioGroup
but you can apply it for RadioButton
.
Follow these steps:
Make RadioButton
object and initialise it with last item of RadioGroup
.
RadioButton lastRadioBtn = (RadioButton) view.findViewById(R.id.lastRadioBtn);
Code below check if RadioGroup
had been checked and also sets error if not.
if(group.getCheckedRadioButtonId()<=0){//Grp is your radio group object
lastRadioBtn.setError("Select Item");//Set error to last Radio button
}
EDIT:
If you wish to clear Error:
lastRadioBtn.setError(null);
Hope this will help.