I'm trying to implement endless scrolling with recyclerview and it works fine. However, I noticed when the content size is smaller than the screen height, onScrolled is never called. I want to load more when scrolling down but I can't detect a scroll down gesture as onScrolled is never called and thus I can't get the dy value. I was wondering:
1) How can I get the scroll direction in this case 2) What's the best practice for situations like this? I am getting a set number of items per service call. What happens if the number of items returned does not fill the screen?
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
{
int lastVisibleItemPosition, visibleItemCount, totalItemCount;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
super.onScrolled(recyclerView, dx, dy);
if(dy>0)
{
visibleItemCount = recyclerLayoutManager.getChildCount();
totalItemCount = recyclerLayoutManager.getItemCount();
lastVisibleItemPosition = recyclerLayoutManager.findLastVisibleItemPosition();
if (lastVisibleItemPosition >= totalItemCount)
{
if (!loading && dy>0 && moreToload)
{
loadMore();
}
}
}
}
});
Thanks!