android - listview按位置获取项目视图我有自定义适配器(基本适配器)的listview。我想按位置从listview获取视图。我试过了mListView.getChildAt(position),但它没有用。如何按位置获取项目视图?
3 回答
![?](http://img1.sycdn.imooc.com/5333a1d100010c2602000200-100-100.jpg)
慕哥6287543
TA贡献1831条经验 获得超10个赞
用这个 :
public View getViewByPosition(int pos, ListView listView) { final int firstListItemPosition = listView.getFirstVisiblePosition(); final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1; if (pos < firstListItemPosition || pos > lastListItemPosition ) { return listView.getAdapter().getView(pos, null, listView); } else { final int childIndex = pos - firstListItemPosition; return listView.getChildAt(childIndex); }}
- 3 回答
- 0 关注
- 594 浏览
添加回答
举报
0/150
提交
取消