我如何在ExpandableListView第一/最后一个可见组的指数? [英] How do I get index of first/last visible group in an ExpandableListView?

查看:326
本文介绍了我如何在ExpandableListView第一/最后一个可见组的指数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得第一个/最后一个可见一群指数在ExpandableListView?

How do I get index of first/last visible group in an ExpandableListView?

getFirstVisiblePosition()和getLastVisiblePosition()大多是无用的ExpandableListViews,因为它们返回列表中的第一个/最后一个可见的细胞的指数。这有差别,因为扩大组算作多个单元格。

getFirstVisiblePosition() and getLastVisiblePosition() are mostly useless for ExpandableListViews, because they return the index of the first/last visible cell in the list. Which makes a difference because expanded groups count as multiple cells.

我所需要的是无论是一些方法,如getFirstVisibleGroupIndex(),getLastVisibleGroupIndex()或某种方法从方法转换可见单元格指数值大于一个真正的组(+孩子)指标值。

What I do need is either some methods like getFirstVisibleGroupIndex(), getLastVisibleGroupIndex() or some method to convert the "visible cell index" value from the methods above to a real group(+child) index value.

注:OnScrollListener.onScroll(...,INT firstVisibleItem,INT visibleItemCount,...)同样的问题受到影响,如果监听器被设置在一个ExpandableListView

Note: OnScrollListener.onScroll(..., int firstVisibleItem, int visibleItemCount, ...) suffers from the same problem if the listener is set on an ExpandableListView.

推荐答案

您是否正在寻找这样的事情?

Are you looking for something like this?

public void listVisibleRowsForExpandableGroup()
{
    int firstVis  = getFirstVisiblePosition();
    int lastVis = getLastVisiblePosition();

    int count = firstVis;

    while (count <= lastVis)
    {
        long longposition = getExpandableListPosition(count);
        int type = getPackedPositionType(longposition);
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            int groupPosition = getPackedPositionGroup(longposition);
            int childPosition = getPackedPositionChild(longposition);
            Log.d("Test","group: " + groupPosition + " and child: " + childPosition );
        }
        count++;

    }
}

这篇关于我如何在ExpandableListView第一/最后一个可见组的指数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆