机器人 - 列表视图获取项目视图按位置 [英] android - listview get item view by position
本文介绍了机器人 - 列表视图获取项目视图按位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的ListView自定义适配器(底座适配器)。我想通过位置获取视图列表视图从。我试过 mListView.getChildAt(位置)
,但它不工作。我怎样才能通过位置获取项目的看法?
I have listview with custom adapter (base adapter). I want to get view from listview by position. I tried mListView.getChildAt(position)
, but it is not working. How can i get item view by position?
推荐答案
使用这样的:
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);
}
}
这篇关于机器人 - 列表视图获取项目视图按位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文