您的位置:首页 > 其它

解决OnscrollListener中Listview.getChildAt()为null问题

2016-04-27 20:23 447 查看
原因是listview子view只有可视范围部分

public View getViewByPosition(int pos, XListView listView) {
try {
final int firstListItemPosition = listView
.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition
+ listView.getChildCount() - 1;

if (pos < firstListItemPosition || pos > lastListItemPosition) {
//This may occure using Android Monkey, else will work otherwise
return listView.getAdapter().getView(pos, null, listView);
} else {
final int childIndex = pos - firstListItemPosition;
return listView.getChildAt(childIndex);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}


参考

https://gist.github.com/AizazAZ/3880ea62131cdd2c631f
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: