radio button - Ensure one of the RadioButton in a RadioGroup is selected in Android -


if have following radiogroup:

<radiogroup     android:id="@+id/rgtype"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_weight="6" >      <radiobutton         android:id="@+id/rbbrides"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:checked="true"         android:text="bridge" />      <radiobutton         android:id="@+id/gbtunnel"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="tunnel" />      <radiobutton         android:id="@+id/rbhighway"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="highway" /> </radiogroup> 

and want following check:

if (rgtype selected) { system.out.println("ok"); } if (rgtype void/null/not selected) { system.out.println("choose @ least 1 selection"); } 

can use ischecked() used individual radio buttons, following?

if (rgtype.ischecked()) {  } else { } 

you can use getcheckedradiobuttonid , see if 1 of radiobuttons checked. i'm not sure returns if none either null or more -1. either way, run , see returns.

i believe return -1 if nothing checked try

  if (rgtype == -1)   {       system.out.println("choose @ least 1 selection");           }   else   {        system.out.println("ok");     } 

radiogroup


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -