鏈接的答案,我認爲是說你應該保持跟蹤你的檢查組的狀態的一個數組列表。然後,在你的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