博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android CheckBox与监听
阅读量:7174 次
发布时间:2019-06-29

本文共 633 字,大约阅读时间需要 2 分钟。

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

转载于:https://www.cnblogs.com/zhaoleigege/p/5159830.html

你可能感兴趣的文章
org.apache.zookeeper.ZooKeeper.<init>(Z)V
查看>>
区块链100讲:共识算法的比较-Casper vs Tendermint
查看>>
Redis 中 set 与 hset 区别与使用
查看>>
Spring Cloud Spring Boot mybatis分布式微服务云架构(一)快速入门
查看>>
编程学习总结python之路之字符编码(改进版1)(图)
查看>>
命令设计模式
查看>>
10.34 linux系统日志 10.35 screen工具
查看>>
02、redis如何通过读写分离来承载读请求QPS超过10万+?
查看>>
Qt之二维绘图:QGraphicsScene与QGraphicsView的关系
查看>>
vi命令详解
查看>>
qtcreator 界面启动
查看>>
模块打包
查看>>
lombok的使用和原理
查看>>
浏览器异步队列执行优先级
查看>>
maven web project in intellij
查看>>
OSChina 娱乐弹弹弹——将程序猿表白方式进行到底!
查看>>
OSChina 周四乱弹 —— 人生处处是深坑
查看>>
OSChina 周日乱弹 —— 如何处理学生早恋
查看>>
OSChina 周日乱弹 ——什么姑娘是女!王!大!人!
查看>>
OSChina 周二乱弹 —— 以后我偷小鱼干养你
查看>>