1.在xml文件中定义CheckBox,一定要定义id
<CheckBox android:id="@+id/beijing" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="北京" />
2.在对应的Java文件中声明对象并赋值
//对控件对象进行声明 CheckBox beijing=null;
beijing=(CheckBox)findViewById(R.id.beijing);
3.设置监听事件
beijing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ editText1.setText(buttonView.getText()+"选中"); }else{ editText1.setText(buttonView.getText()+"取消选中"); } } });