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;
}
}
}
调试下,看下具体哪个变量是null的。
大概知道是什么原因了,重写的类不会被系统框架回调 不知道怎么解决