<CheckBox
  android: />

 

//实例化  CheckBox
cb1 = (CheckBox) findViewById(R.id.cb1);

cb1.setOnCheckedChangeListener(this);

 

//重写监听器的抽象函数
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  //buttonView 选中状态发生改变的那个按钮
  //isChecked 表示按钮新的状态(true/false)
  if (cb1 == buttonView) {
    if (isChecked) {
    //显示一个提示信息  
    toastDisplay(buttonView.getText() + "选中");

    } else {
      toastDisplay(buttonView.getText() + "取消选中");
    }
  }
}

相关文章:

  • 2022-12-23
  • 2021-12-20
  • 2021-11-10
  • 2022-02-19
  • 2021-12-17
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案