如何在ExpandableListView中获取第一个/最后一个可见组的索引?
getFirstVisiblePosition()和getLastVisiblePosition()对于ExpandableListViews几乎没用,因为它们返回列表中第一个/最后一个可见单元格的索引.这有所不同,因为扩展组计为多个单元格.
我需要的是一些方法,如getFirstVisibleGroupIndex(),getLastVisibleGroupIndex()或某些方法将"可见单元索引"值从上面的方法转换为实际组(+子)索引值.
注意:如果在ExpandableListView上设置了侦听器,则OnScrollListener.onScroll(...,int firstVisibleItem,int visibleItemCount,...)会遇到同样的问题.
小智 10
你在找这样的东西吗?
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++;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这个问题很旧,但是对于像我一样偶然发现它的每个人...根据sara的回答,这是我现在使用的方法:
public int getFirstVisibleGroup() {
int firstVis = list.getFirstVisiblePosition();
long packedPosition = list.getExpandableListPosition(firstVis);
int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition);
return groupPosition;
}
Run Code Online (Sandbox Code Playgroud)
同样,getLastVisiblePosition()也可以使用...
| 归档时间: |
|
| 查看次数: |
3819 次 |
| 最近记录: |