Recipe Using Radio Buttons

A radio button is like a checkbox that cannot be unchecked. Selecting one radio button unselects a previously selected one. Usually a group of radio buttons is put into a RadioGroup view group that ensures only one button of the collection is selected at a time.This is shown in the layout file in Listing 4.18.

LayoutWidgets

Figure 4.13 ToggleButton example with unselected and selected widgets.

Listing 4.18 res/layout/rbutton.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioGroup android:id="@+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:text="Republican" android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" <RadioButton android:text="Democrat"

android:id="@+id/RadioButton03" android:layout_width="wrap_content" android:layout_height="wrap_content" <RadioButton android:text="Independent" android:id="@+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content"

</RadioGroup>

</LinearLayout>

An example activity is similar to the previous recipe in Listing 4.17, but with CheckBox replaced by RadioButton. Listing 4.18's layout is shown in Figure 4.14.

LayoutWidgets

^^ Republican

^^ Democrat ^^Independent

Figure 4.14 RadioGroup example showing three radio buttons.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook


Post a comment