Root, Parent, Child
多亏了一些教程,我已经创建了一个 3 级 ( ) 自定义 ExpandableListView 和相关的适配器。我有显示故障Parent
列表的水平,而Root
与Child
级别正确显示。我发现该Parent
级别将其视图复制 N 次,其中 N 是Parent
组中元素的数量。
我要的是:佳能下的三类
我得到的是:佳能下的三个类别重复了3次
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)
无论创建Root
了多少个子 ( Parent
) 视图,of level 每次都会返回正确的数字。我不知道为什么getGroupView
会被反复调用该Parent
级别。
Parent
等级:
@Override
public Object getGroup(int groupPosition)
{
/* _listDataHeader is the same ArrayList<String> lensTypeList from above */
return this._listDataHeader.get(groupPosition);
}
您不应该将 anArrayList<String>
作为第二级 ExpandableListView 的标头传递吗?如果我将第二级String
作为标题传递给单个级别,我只能达到预期的结果,但这打破了我查找Child
级别视图的逻辑,因为groupPosition
一直0
以来_listDataHeader.size() == 1
提前感谢您的任何帮助/建议。:)
在这里找到答案:https : //stackoverflow.com/a/35208411/5004391
我真的不明白为什么,但我必须对要返回getChildrenCount(int groupPosition)
的Root
级别进行硬编码1
,而不是实际的孩子数量。在我的应用程序的其他ExpandableListView
s 中,我总是返回孩子的数量并且它按预期工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句