The use of Android RadioButton and checkboxes-android Learning Journey (19)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.