I created a RecyclerView for my application and trying to find a way to stop huge requests, I want to get the results 10 by 10 with a progress bar. My server will send the r
You can try this approach:
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
{
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) //check for scroll down
{
visibleItemCount = mLayoutManager.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisibleItems = mLayoutManager.findFirstVisibleItemPosition();
if (loading) {
if ((visibleItemCount + pastVisibleItems) >= totalItemCount) {
loading = false;
if (adapter.countOfShowing < adapter.allChallenges.size()) {
Log.e("...", "Last Item Wow !");
adapter.increaseCountOfShowing();
adapter.notifyDataSetChanged();
}
loading = true;
//Do pagination.. i.e. fetch new data
}
}
}
}
});