How to implement endless list with RecyclerView?

前端 未结 30 2689
无人及你
无人及你 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:10

    There is a method public void setOnScrollListener (RecyclerView.OnScrollListener listener) in https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html#setOnScrollListener%28android.support.v7.widget.RecyclerView.OnScrollListener%29. Use that

    EDIT:

    Override onScrollStateChanged method inside the onScrollListener and do this

                boolean loadMore = firstVisibleItem + visibleItemCount >= totalItemCount;
    
                //loading is used to see if its already loading, you have to manually manipulate this boolean variable
                if (loadMore && !loading) {
                     //end of list reached
                }
    

提交回复
热议问题