ExpandableListView第一个孩子

时间:2015-04-13 21:07:00

标签: android expandablelistview

有没有办法获得每组的第一个孩子的索引而不管显示在屏幕上的位置?我使用0作为索引,但当我开始向上和向下滚动页面时,它会对所有孩子应用更改,我怀疑因为child [0]不再是组中的第一个,而是屏幕上的第一个。

2 个答案:

答案 0 :(得分:0)

您必须使用适配器来获取此索引(假设您的项目具有索引) yourExpandableAdapter.getChild(groupPosition, childPosition).getIndex();

其中getIndex()是适配器项对象中的方法。

答案 1 :(得分:0)

可扩展列表视图包含每个组的组和子项。覆盖BaseExpandableListAdapter(或您正在使用的子类)的getChildId。调用方法getChildID(0,0)。 list_parents是一个持有每个组的arraylist。在此示例中,每个组元素都包含内部的所有子项。如果您有不同的数据结构,组和子项遵循类似的方式。

@Override
public long getChildId(int groupPosition, int childPosition) {
    if (groupPosition < 0 || childPosititon < 0)
        return null;
    else
        returnthis.list_children.get(list_parents.get(groupPosition))
                .get(childPosititon);
}