ExpandableListView + checkbox在使用该组合控件的时候,遇到当勾选之后滚动控件,会发现之前选中项重新自动变回了没有选中状态,这个问题弄的我无从下手,不断梳理代码逻辑,没有问题,断点跟踪,,,,就是找不到原因,灵魂在Google游荡中,无意间发现一篇国外帖子,说是滚动自动触发oncheckedchanged();感觉整个世界都蒙 b 了。断点就是自动触发,就是不知道为啥,强迫症驱使我去找问题根源,,,,反而挖坑把自己埋了,最后的解决办法就是在 gechildview()设置oncheckedchanged监听前,将CheckBox
oncheckedchangelistener() 事件设置为null ,再重新监听,贴上解决源码,强迫症惨痛教训,!!!!!
@Override
public View getChildView(final int groupPosition, final int childPosition
, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder childHolder;
VideoCacheT vt = (VideoCacheT) getChild(groupPosition, childPosition);
if (convertView == null) {
childHolder = new ChildHolder();
childHolder.cbSelect = (CheckBox) convertView.findViewById(R.id.cache_cbSelect);
convertView.setTag(childHolder);
} else {
childHolder = (ChildHolder) convertView.getTag();
}
childHolder.course_item_videostxt.setText(EduolGetUtil.DataForString(vt.getSection_name()));
//编辑状态显示勾选框
if (!vicbSelect) {
childHolder.cbSelect.setVisibility(View.GONE);
} else {
childHolder.cbSelect.setVisibility(View.VISIBLE);
}
childHolder.cbSelect.setOnCheckedChangeListener(null); //然后设置CheckBox状态,,这是重点,,,
boolean sebln = ((getIsSelected().get(vt.getSection_id())) != null ? (getIsSelected().get(vt.getSection_id())) : false);
childHolder.cbSelect.setChecked((sebln));
childHolder.cbSelect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
VideoCacheT vct = (VideoCacheT) getChild(groupPosition, childPosition);
if (isChecked) {
//点击勾选 // 文件在 DataChange 时调用setOnCheckedChangeListener 同步
mSelectedDownloadSectionids.put(String.valueOf(vct.getSection_id()), String.valueOf(vct.getSection_id()));
//选择下载文件
mOnItemSelectListener.onSelected(vct, mSelectedDownloadSectionids);
//标记专状态
getIsSelected().put(vct.getSection_id(), true);
} else {
mSelectedDownloadSectionids.remove(String.valueOf(vct.getSection_id()));
//不选择
mOnItemSelectListener.onNoneSelect(vct, mSelectedDownloadSectionids);
//标记专状态
getIsSelected().put(vct.getSection_id(), false);
}
}
});
setBackgroundOnClickListener(childHolder.cbSelect, convertView, vt);
return convertView;
}