How to implement Infinite Scrolling with RecyclerView?

前端 未结 5 1856
一生所求
一生所求 2020-12-20 00:03

I have a recycler and inside of it there are cardviews where I fetch information from a REST service, I\'m trying to implement an endless scroll, It\'s supposed that user wi

5条回答
  •  旧时难觅i
    2020-12-20 00:15

    Make a static boolean variable named "ready" and initialize it to false.

    Add the if ready condition in the onLoadMore method as below.

    public boolean onLoadMore(int page, int totalItemsCount) {
             if (ready) {
               //load more from API
             }         
       return false;
    }
    

    set ready to true in onBindViewHolder when the position of item is last.

提交回复
热议问题