Monday, July 9, 2012

RadioButton and RadioGroup in Andorid

A radio button is a two-states button that can be either checked or unchecked. When the radio button is unchecked, the user can press or click it to check it. However, contrary to a CheckBox, a radio button cannot be unchecked by the user once checked.

Radio buttons are normally used together in a RadioGroup. When several radio buttons live inside a radio group, checking one radio button unchecks all the others.




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<RadioGroup
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:checkedButton="@+id/option1"
 android:id="@+id/radiogrooup">
<RadioButton
 android:text="Option 1"
 android:id="@+id/option1"/>
<RadioButton
 android:text="Option 2"
 android:id="@+id/option2"/>
<RadioButton
 android:text="Option 3"
 android:id="@+id/option3"/>
<RadioButton
 android:text="Option 4"
 android:id="@+id/option4"/>
</RadioGroup>
</LinearLayout

No comments:

Post a Comment