Endless RecyclerView with ProgressBar for pagination

前端 未结 9 2177
庸人自扰
庸人自扰 2020-11-27 12:51

I am using a RecyclerView and fetching objects from an API in batches of ten. For pagination, I use EndlessRecyclerOnScrollListener.

It\'s all working properly. Now

9条回答
  •  失恋的感觉
    2020-11-27 13:20

    There is another way to do this.

    • First your adapter's getItemCount returns listItems.size() + 1

    • return VIEW_TYPE_LOADING in getItemViewType() for position >= listItems.size(). This way the loader will only be shown at the end of the recycler view list. The only problem with this solution is even after reaching the last page, the loader will be shown, so in order to fix that you store the x-pagination-total-count in the adapter, and

    • then you change the condition to return view type to

      (position >= listItem.size())&&(listItem.size <= xPaginationTotalCount) .

    I just came up with this idea now what do you think?

提交回复
热议问题