我有一个自定义的3级可扩展列表视图。用2个适配器完成,扩展BaseExpandableListAdapter
:ParentAdapter
和ChildAdapter
。
在getChildView
的{{1}}内,我只是召唤ParentAdapter
。
但是,当我展开第3级并将其滚出视图时,它会将自身恢复到折叠状态。
我该如何解决这个问题?
我想,我必须为ChildAdapter中的ChildAdapter
保存展开/折叠状态,但我不知道如何正确实现它。
或者我应该在ParentAdapter中保存getGroupView
的状态吗?
答案 0 :(得分:0)
好吧,看起来,我已经完成了。
首先,在内部添加额外参数isExpanded
。
在ParentAdapter
内getChildView
添加条件:
//expand child if was previously expanded
if (item.isExpanded)
{
expandableListView.expandGroup(childPosition);
}
在ChildAdapter
内getChildView
添加以下内容:
if (item.isExpanded)
{
expandableListView.expandGroup(groupPosition);
notifyDataSetChanged();
} else {
expandableListView.collapseGroup(groupPosition);
notifyDataSetChanged();
}
这将保存商品的展开/折叠状态并正确更改。
至少,这个实现解决了我的问题,但是,可能存在更好的解决方案。