Introduction to RadioButton and checkboxes
The radio button (RadioButton) and check box (checkbox) Inherit the button, so the property is set to the button almost, but adds a android:chencked property.
Used to set whether or not to be selected.
The difference between a RadioButton and a checkbox
The former if only one of the groups can only be selected, once is usually used with Radiogroup, the latter is not limited.
Instance
<LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android" Xmlns:tools="Http://schemas.android.com/tools" Android:layout_width="Match_parent" Android:layout_height="Match_parent" Android:paddingleft="@dimen/activity_horizontal_margin" Android:paddingright="@dimen/activity_horizontal_margin" Android:paddingtop="@dimen/activity_vertical_margin" Android:paddingbottom="@dimen/activity_vertical_margin" Tools:context=". Mainactivity " android:orientation="Vertical"> <TableRow android:layout_width="Wrap_content"android:layout_height= "Wrap_content"> <TextView android:layout_width="Wrap_content"android:layout_height ="Wrap_content"android:text="Gender:"android:textsize="16px" /> <radiogroup android:o Rientation = "horizontal" android:id =< Span class= "Hljs-value" > "@+id/rg" android:layout_gravity =" center_horizontal " android:layout_width =" match_parent " android:layout_height =" wrap_content "; <RadioButtonandroid:layout_width="Wrap_content"android:layout_height ="Wrap_content"android:text= "male"android:checked="true"/> <RadioButtonandroid:layout_width="Wrap_content"android:layout_ Height="Wrap_content"android:text="female" /> </radiogroup> </TableRow> <TableRow android:layout_height="Wrap_content"android:layout_width= "Wrap_content"> <TextView android:layout_width="Wrap_content"android:layout_ Height="Wrap_content"android:text="Favorite Color"android:textsize= "16px"/> <CheckBox android:layout_width="Wrap_content"android:layout_height= "Wrap_content" Android:text="Red"/> <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"/> </TableRow> <TableRow android:layout_height="Match_parent"android:layout_ Width="Match_parent"> <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" Android:text="show"/> </TableRow></linearlayout>
The use of Android RadioButton and checkboxes-android Learning Journey (19)