I want to implement load more in Recyclerview. Here is the code. The code is from github. https://gist.github.com/ssinss/e06f12ef66c51252563e
MainActivity code:
I found an answer here that, I believe, is much better than most I've seen on SO and elsewhere.
The idea is simple: in onScrolled in your RecyclerView's ScrollListener, check if the last completely visible item is the last item in your data set.
if(llm.findLastCompletelyVisibleItemPosition() == data.length() -1){
//bottom of list!
loadMoreData();
}
This happens with a method in the LinearLayoutManager
. Calling LinearLayoutManager#findLastCompletelyVisibleItemPosition()
can comparing it to the position of the last item in your dataset let's you know when you can load more.
I haven't tried this for the GridLayoutManager
.
UPDATE
LinearLayoutManager#findLastVisibleItemPosition()
is a better alternative to LinearLayoutManager#findLastCompletelyVisibleItemPosition()
, especially when your items are longer than the window height.