import java.util.List;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class Boxlistener implements OnCheckedChangeListener{
private int type;
private CheckBox cball;
private List<CheckBox> boxs ;
private boolean bool;
public static final int PARENT_BOX=0;
public static final int CHILD_BOX=1;
public Boxlistener(int type) {
this.type = type;
}
public Boxlistener(int type, CheckBox cball, List<CheckBox> boxs) {
this.type = type;
this.cball = cball;
this.boxs = boxs;
}
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
switch (type) {
case PARENT_BOX:
Log.i("delong","此时父类状态为:"+cball.isChecked());
cball.setChecked(true);
if (cball.isChecked()) {
for (CheckBox box : boxs) {
box.setChecked(true);
}
}else{
if (!bool) {
for (CheckBox box : boxs) {
box.setChecked(false);
}
}else{
bool=false;
}
}
break;
case CHILD_BOX:
Log.i("delong", "当前box状态为:"+cball.isChecked());
if (cball.isChecked()) {
Log.e("delong", "当前box状态为:"+isChecked);
if (isChecked) {
}else{
bool = true;
cball.setChecked(false);
}
}else{
if (isChecked) {
for (int i=0 ; i<boxs.size();i++) {
for(int j= i+1;j<boxs.size();j++){
if ((""+boxs.get(j).isChecked()).equals(""+boxs.get(j-1).isChecked())) {
if (j==boxs.size()-1) {
cball.setChecked(true);
}
}else{
return;
}
}
}
}
}
break;
}
}
}
关于Checbox的OnCheckedChangeListener为什么我写个外部内传控件过来一直空指针,写内部内没问题?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答
- threenewbee 2016-05-01 20:31关注
调试下,看下具体哪个变量是null的。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 寻一个支付宝扫码远程授权登录的软件助手app
- ¥15 解riccati方程组
- ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
- ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
- ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
- ¥50 树莓派安卓APK系统签名
- ¥65 汇编语言除法溢出问题