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 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 保护模式-系统加载-段寄存器