java - Checking radio group either empty/null -
i want check in android radiogroup empty or null i.e submitted without clicking on radio button in group??
xml code
<radiogroup android:id="@+id/lift" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <radiobutton android:paddingright="50dip" android:textsize="20dp" android:id="@+id/r91" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/yes" /> <radiobutton android:paddingright="50dip" android:textsize="20dp" android:id="@+id/r92" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no" /> </radiogroup> activity code
radiogroup radiogroup1 = (radiogroup) findviewbyid(r.id.lift); if(radiogroup1=='null') { toast.maketext(getapploicationcontext(),"first radiogroup null",toast.length_long).show(); }
use below method checked radio button id, if returns -1 ,means user didn’t selected radio button.
radiogroup.getcheckedradiobuttonid(); // homecoming unique id of checked radio button or -1 on empty selection. see doc here >> getcheckedradiobuttonid();
public int getcheckedradiobuttonid () returns identifier of selected radio button in group. upon empty selection, returned value -1.
related xml attributes android:checkedbutton
returns
the unique id of selected radio button in grouping edit :-
if(radiogroup1.getcheckedradiobuttonid() == -1) { //empty selection } else { // user selected 1 radio button. } java android
No comments:
Post a Comment