Apr 13, 2012

How to Make a Default Radio Button in Android

,


The radio button "checked" property indicates to the Android device which radio button is the default value. This means that when the user opens the screen, a radio button is automatically selected. The user can still change the radio button selected, but this method ensures that a value is always selected, so you never receive a blank value for the radio button group you display on the screen.

Instructions

    • 1
      Open the Java Eclipsed developer software for Android projects. Open your Android project and double-click the XML file that contains the radio button group.
    • 2
      Locate the radio button group you want to edit. The following code is an example of two radio buttons for an Android view:
      <RadioGroup android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:id="@+id/radioPreferences">
      <RadioButton android:checked="false"
      android:id="@+id/onOption" android:text="On"/>
      <RadioButton android:checked="false"
      android:id="@+id/onOption" android:text="Off"/>
      </RadioGroup>
      Notice the "checked" property. You use this property to set a default radio button.
    • 3
      Change one of the radio button's "checked" property to "true" to set it as the default. Save the changes and click the "Run" button to see the new default radio button.
 

HowToYo Copyright © 2011 | Template design by O Pregador | Powered by Blogger Templates