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.