Radiobutton is the single-choice button, and checkbox is the check button, that is, multiple options can be selected at the same time. The following program defines a set of radio buttons and three check boxes to allow users to select user-related information. The radio button must be placed in a RadioGroup to achieve the radio effect.
<? Xml version = "1.0" encoding = "UTF-8"?>
<TableLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<TableRow>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Gender :"
Android: textSize = "11pt"
/>
<! -- Define a group of single partitions -->
<RadioGroup
Android: orientation = "horizontal"
Android: layout_gravity = "center_horizontal">
<! -- Define two single partitions -->
<RadioButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "male"
/>
<RadioButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "female"
/>
</RadioGroup>
</TableRow>
<TableRow>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "favorite colors :"
Android: textSize = "11pt"
/>
<! -- Define a vertical linear layout -->
<LinearLayout android: layout_gravity = "center_horizontal"
Android: orientation = "vertical"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
>
<! -- Define three check boxes -->
<CheckBox android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "red"
Android: checked = "true"
/>
<CheckBox android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "blue"
/>
<CheckBox android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "green"
/>
</LinearLayout>
</TableRow>
</TableLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<TableLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<TableRow>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Gender :"
Android: textSize = "11pt"
/>
<! -- Define a group of single partitions -->
<RadioGroup
Android: orientation = "horizontal"
Android: layout_gravity = "center_horizontal">
<! -- Define two single partitions -->
<RadioButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "male"
/>
<RadioButton android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "female"
/>
</RadioGroup>
</TableRow>
<TableRow>
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "favorite colors :"
Android: textSize = "11pt"
/>
<! -- Define a vertical linear layout -->
<LinearLayout android: layout_gravity = "center_horizontal"
Android: orientation = "vertical"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
>
<! -- Define three check boxes -->
<CheckBox android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "red"
Android: checked = "true"
/>
<CheckBox android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "blue"
/>
<CheckBox android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "green"
/>
</LinearLayout>
</TableRow>
</TableLayout>
From the column hn307165411