链接的答案,我认为是说你应该保持跟踪你的检查组的状态的一个数组列表。然后,在你的BaseExpandableListAdapter您getChildView方法,你会做检查,以查看是否为子组存在..
这里是我的实现,我使用一个HashMap,而不是一个ArrayList:
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
CheckBox check__bookmark = (CheckBox)child_row.findViewById(R.id._checkBox);
if (mapp.group_bookmark_s_checked.containsKey((groupPosition))==true)
check__bookmark.setChecked(true);
else
check__bookmark.setChecked(false);
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
CheckBox PlayGroupSelected = (CheckBox)group_row.findViewById(R.id.bookmark_group_checkBox);
if (mapp.group_bookmark_s_checked.containsKey((groupPosition))==true)
PlayGroupSelected.setChecked(true);
else
PlayGroupSelected.setChecked(false);
PlayGroupSelected.setOnCheckedChangeListener(new BookmarkGroupCheckedChangeListener(groupPosition, mapp, group_row));
现在您的听众通过删除和添加到您的状态对象管理的状态。我用notifyDataSetChanged(),因为孩子们不刷新一次的检查状态变化绘制。不知道如果这是解决问题的正确方法,但它的伎俩。
class BookmarkGroupCheckedChangeListener implements OnCheckedChangeListener {
private int mPosition;
MyApplication mapp;
RelativeLayout mgroup_row;
BookmarkGroupCheckedChangeListener(int position, MyApplication app, RelativeLayout group_row) {
mapp = app;
mPosition = position;
mgroup_row = group_row;
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked == true) {
mapp.group_bookmark_s_checked.put((mPosition), new Boolean(true));
Log.v("DEBUG:", "Group Bookmark Checked On at " + mPosition);
notifyDataSetChanged();
}
else if (mapp.group_bookmark_s_checked.containsKey(mPosition)){
mapp.group_bookmark_s_checked.remove((mPosition));
Log.v("DEBUG:", "Checked Off at " + mPosition);
notifyDataSetChanged();
}
}
}
是。 notifyDataSetChanged();很重要。坦克 – IndieBoy