【发布时间】:2017-10-27 00:48:47
【问题描述】:
感谢一些教程,我创建了一个 3 级 (Root, Parent, Child) 自定义 ExpandableListView 和相关适配器。我无法显示列表的Parent 级别,而Root 和Child 级别显示正确。我发现Parent 级别正在将其视图复制N 次,其中N 是Parent 组中的元素数。
我想要的: Three categories under Canon
我得到了什么: The three categories under Canon are duplicated 3 times
Root等级:
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
/* this list is the header of the Parent level, and I know it has the correct number of elements */
List<String> lensTypeList = listDataChild.get(_listDataHeader.get(groupPosition));
/* the Parent level of the ExpandableListView */
LensSecondLevel lensSecondLevel = new LensSecondLevel(ManageLensesActivity.this);
/* all params other than lensTypeList work correctly in the later levels */
lensSecondLevel.setAdapter(new SecondLevelListViewAdapter(ManageLensesActivity.this, lensTypeList, lensMap, lensPositionIndicesMap));
getChildrenCount(int groupPosition) of Root 级别每次都返回正确的数字,尽管创建了多少子 (Parent) 视图。我不知道为什么getGroupView 被重复调用Parent 级别。
Parent等级:
@Override
public Object getGroup(int groupPosition)
{
/* _listDataHeader is the same ArrayList<String> lensTypeList from above */
return this._listDataHeader.get(groupPosition);
}
您不应该传递ArrayList<String> 作为第二级 ExpandableListView 的标题吗?如果我通过第二级单个@987654339@ 作为标题,我只能达到预期的结果,但这打破了我查找Child 级别视图的逻辑,因为groupPosition 始终是0,因为_listDataHeader.size() == 1
提前感谢您提供任何帮助/建议。 :)
【问题讨论】:
标签: android expandablelistview expandablelistadapter