Monday 4 April 2011

Radio Button and Radio Group

You use radio button to allow users to select certain item from several options. What if you want to allow user to select only one item? You can use Radio Group.

In the layout folder, open the main.xml file and put in the following code:-

<RadioGroup android:layout_width="fill_parent"
android:layout_height="fill_parent"
 android:orientation="vertical"
 android:id="@+id/QueGroup1">

            <RadioButton android:text=" Option 1..........."
            android:textColor="#ffff00"
             android:id="@+id/RadioButton01"
             android:layout_width="wrap_content"
             android:checked="true"
             android:layout_height="wrap_content">
             </RadioButton>
            
             <RadioButton android:text=" Option 2.........."
             android:textColor="#ffff00"
             android:id="@+id/RadioButton02"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"></RadioButton>
</RadioGroup>

User can only select one item (either Option 1 OR option 2) from the Radio Group. Hope that will help.


Roger,
~mytikus

No comments: