通过位置找到ListView中的某个item的View

来源:互联网 发布:如何重新设置网络账号 编辑:程序博客网 时间:2024/05/16 11:34
/**     * 通过位置找到ListView中的某个item的View     * @param pos     * @param listView     * @return     */    public View getViewByPosition(int pos, ListView listView) {        int firstListItemPosition = listView.getFirstVisiblePosition();        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);        }    }

亲测,可用。

0 0
原创粉丝点击