下面为实例代码:
private CheckBox location;
location = (CheckBox)findViewById(R.id.location);
location.setTextColor(Color.BLACK);
location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
// 判断当前checkbox的状态,是否选中
if(location.isChecked()){
Toast.makeText(Sendmessage.this,"已选中checkbox",Toast.LENGTH_LONG).show();
// 将checkbox设置为未选中状态
location.setChecked(false);
}else{
Toast.makeText(Sendmessage.this,"未选中checkbox",Toast.LENGTH_LONG).show();
// 将checkbox设置为选中状态
location.setChecked(true);
}
}
});
![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)