【问题标题】:Android: Multi-level ExpandableListView displaying children multiple timesAndroid:多次显示子级的多级ExpandableListView
【发布时间】:2017-10-27 00:48:47
【问题描述】:

感谢一些教程,我创建了一个 3 级 (Root, Parent, Child) 自定义 ExpandableListView 和相关适配器。我无法显示列表的Parent 级别,而RootChild 级别显示正确。我发现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&lt;String&gt; 作为第二级 ExpandableListView 的标题吗?如果我通过第二级单个@9​​87654339@ 作为标题,我只能达到预期的结果,但这打破了我查找Child 级别视图的逻辑,因为groupPosition 始终是0,因为_listDataHeader.size() == 1

提前感谢您提供任何帮助/建议。 :)

【问题讨论】:

    标签: android expandablelistview expandablelistadapter


    【解决方案1】:

    在这里找到答案:https://stackoverflow.com/a/35208411/5004391

    我真的不明白为什么,但我不得不硬编码getChildrenCount(int groupPosition) 以获得Root 级别以返回1,而不是实际的孩子数量。在我的应用程序的其他ExpandableListViews 中,我总是返回孩子的数量,它按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      • 2013-01-27
      • 1970-01-01
      相关资源
      最近更新 更多