I am trying to implement Endless Infinite Scrolling with RecyclerView, but I am only getting first 10 records, not getting next 10 records and even not getting any progress
for (int i = start + 1; i < end; i++) {
studentList.add(add data here) ;
mAdapter.notifyItemInserted(studentList.size());
}
I had the same issue once an I solve it using this code ... First .. create this class
public abstract class EndlessOnScrollListener extends OnScrollListener {
public static String TAG = EndlessOnScrollListener.class.getSimpleName();
// use your LayoutManager instead
private LinearLayoutManager llm;
public EndlessOnScrollListener(LinearLayoutManager sglm) {
this.lm = llm;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (!recyclerView.canScrollVertically(1)) {
onScrolledToEnd();
}
}
public abstract void onScrolledToEnd();
}
Second .. in you activity use this
recyclerView.addOnScrollListener(new EndlessOnScrollListener() {
@Override
public void onScrolledToEnd() {
if (!loading) {
loading = true;
// add 10 by 10 to tempList then notify changing in data
}
loading = false;
}
});
This works for me .... I hope it works for you to.