Android 7th Lesson--checkbutton

Source: Internet
Author: User

1. Layout

<Tablelayoutxmlns: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:orientation= "vertical" ><TableRow>    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Gender:"/>    <RadiogroupAndroid:id= "@+id/rg"android:orientation= "Horizontal"android:layout_gravity= "Center_horizontal" >    <RadioButtonAndroid:id= "@+id/male"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Male" />     <RadioButtonAndroid:id= "@+id/female"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "female" />     </Radiogroup></TableRow><TableRow>    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Favorite Color"/>    <LinearLayoutAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:orientation= "vertical">    <CheckBoxAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Red" />    <CheckBoxAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Blue" />    <CheckBoxAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Green" />    </LinearLayout></TableRow><TextViewAndroid:id= "@+id/show"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"/></Tablelayout>

First, the overall use of the tablelayout, table layout

Then put the radio box that part in the TableRow, there is a TextView and two RadioButton (the two are surrounded by radiogroup to form a whole)

There are also multiple marquee sections, enclosed in TableRow, with three checkboxes enclosed in linearlayout. form a linear layout, vertical direction.

The final is to put a separate TextView display results and so on.

2. Implement the Select box to display a single sentence.

 PackageCom.example.checkbutton;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.RadioGroup;ImportAndroid.widget.RadioGroup.OnCheckedChangeListener;ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {Radiogroup RG;    TextView Show; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); RG=(Radiogroup) Findviewbyid (R.ID.RG); Show=(TextView) Findviewbyid (r.id.show); Rg.setoncheckedchangelistener (NewOncheckedchangelistener () {@Override Public voidOnCheckedChanged (Radiogroup Group,intCheckedid) {                //TODO auto-generated Method StubString Tip=checkedid==r.id.male? "Your sex is a man": "Your sex is a woman";            Show.settext (TIP);    }            }); }}

The whole radiogroup of two radiobox is used as an object to monitor the event.

Using the conditional operator, String Tip=checkedid==r.id.male? "Your sex is a man": "Your sex is a woman";

Finally, SetText.

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.