我的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);
}
}