您的位置:首页 > 移动开发 > Android开发

android CheckBox与监听

2016-01-26 11:41 471 查看
<CheckBox
android:id="@+id/cb1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="CheckBox1" />

//实例化  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() + "取消选中");
    }
  }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: