The first step is to create an Android project.
The second step is to modify the generated Res/layout/main.xml
View Plaincopy to Clipboardprint?
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<checkbox
Android:id= "@+id/checkbox"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "check box 1"/>
<checkbox
Android:id= "@+id/checkbox1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "check box 2"/>
<radiogroup
Android:id= "@+id/radiogroup"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<radiobutton android:id= "@+id/radion1"
Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"
android:text= "Beijing"/>
<radiobutton android:id= "@+id/radion2"
Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"
android:text= "Tianjin"/>
<radiobutton android:id= "@+id/radion3"
Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"
android:text= "Shanghai"/>
<radiobutton android:id= "@+id/radion4"
Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"
android:text= "Chongqing"/>
</RadioGroup>
</LinearLayout>
Step three, add the main code
View Plaincopy to Clipboardprint?
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.CheckBox;
Import Android.widget.CompoundButton;
Import Android.widget.RadioButton;
Import Android.widget.RadioGroup;
Import Android.widget.CompoundButton.OnCheckedChangeListener;
public class CheckBox extends Activity implements Oncheckedchangelistener {
/** called when the activity is first created. */
RadioButton r1 = null;
RadioButton r2 = null;
RadioButton r3 = null;
RadioButton r4 = null;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
CheckBox checkbox = (checkbox) Findviewbyid (R.id.checkbox);
CheckBox checkBox1 = (checkbox) Findviewbyid (R.id.checkbox1);
Get a radio button group
Radiogroup Radiogroup = (radiogroup) Findviewbyid (R.id.radiogroup);
Get radio button
R1 = (RadioButton) Findviewbyid (R.id.radion1);
r2 = (RadioButton) Findviewbyid (R.id.radion2);
R3 = (RadioButton) Findviewbyid (R.id.radion3);
R4 = (RadioButton) Findviewbyid (R.ID.RADION4);
Checkbox.setchecked (TRUE);
R1.setclickable (TRUE);
Monitor Multi-Select button
Checkbox.setoncheckedchangelistener (this);
Checkbox1.setoncheckedchangelistener (this);
Listen radio button
Radiogroup.setoncheckedchangelistener (Mchangeradio);
}