How to implement endless list with RecyclerView?

前端 未结 30 3321
无人及你
无人及你 2020-11-22 02:22

I would like to change ListView to RecyclerView. I want to use the onScroll of the OnScrollListener in RecyclerView to determine if a

30条回答
  •  天命终不由人
    2020-11-22 03:06

    I achieved an infinite scrolling type implementation using this logic in the onBindViewHolder method of my RecyclerView.Adapter class.

        if (position == mItems.size() - 1 && mCurrentPage <= mTotalPageCount) {
            if (mCurrentPage == mTotalPageCount) {
                mLoadImagesListener.noMorePages();
            } else {
                int newPage = mCurrentPage + 1;
                mLoadImagesListener.loadPage(newPage);
            }
        }
    

    With this code when the RecyclerView gets to the last item, it increments the current page and callbacks on an interface which is responsible for loading more data from the api and adding the new results to the adapter.

    I can post more complete example if this isn't clear?

提交回复
热议问题