RecycleView 监听

2017-12-08  本文已影响9人  满船清梦___
recycle.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        if (newState == RecyclerView.SCROLL_STATE_IDLE && adapter != null && lastVisibleItem + 2 == adapter.getItemCount()) {
            presenter.loadMoreData();
        }
        if (newState == RecyclerView.SCROLL_STATE_IDLE && adapter != null) {
            Log.d(TAG, "onScrollStateChanged: " + lastVisibleItem + "--" + linearLayoutManager.findFirstCompletelyVisibleItemPosition() + "--" + linearLayoutManager.findFirstVisibleItemPosition());
            //无法向上滑动表示到达最顶
            if (!recyclerView.canScrollVertically(-1)) {
                CommonUtils.keyBoard(edit, "close");
            }
            /*else if (!recyclerView.canScrollVertically(1)) {
                onScrolledToBottom();
            }*/
        }
    }

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
        // 当dy < 0; 表示向上滑动
        lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
    }
});
上一篇下一篇

猜你喜欢

热点阅读