首页 > 移动平台 > 详细

android CheckBox与监听

时间:2016-01-26 12:36:07      阅读:147      评论:0      收藏:0      [点我收藏+]

<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() + "取消选中");
    }
  }
}

android CheckBox与监听

原文:http://www.cnblogs.com/zhaoleigege/p/5159830.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!