HorizontalListView遇到大数据,需要移动到指定位置如何处理

HorizontalListView 原创的setSelection()是没有实现的,后来有国人重写了HorizontalListView。

在这个类里加入了

    @Override
    public void setSelection(int position) {
        setSelectionFromLeft(position, 0);
    }

    /**
     * Sets the selected item and positions the selection y pixels from the left edge
     * of the ListView. (If in touch mode, the item will not be selected but it will
     * still be positioned appropriately.)
     *
     * @param position Index (starting at 0) of the data item to be selected.
     * @param x        The distance from the left edge of the ListView (plus padding) that the
     *                 item will be positioned.
     */
    public void setSelectionFromLeft(int position, int x) {
        if (setSelectionFrom(position, x) >= 0) {
            requestLayout();
        }
    }

希望可以帮助那些一样遇到过的人,少走点弯路。

你可能感兴趣的:(HorizontalListView遇到大数据,需要移动到指定位置如何处理)