下面爲實例代碼:
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);
}
}
});
!!!!!!!!!!!!!!!!!!!