RecyclerView Endless Infinite Scrolling Issue
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.
Try notifyItemRangeChanged
yourCurrentList.addAll(newData); mAdapter.notifyItemRangeChanged(yourCurretList.size() + 1, newDataSize);
I think this'll help you.
replace
private List<Student> studentList;
with
private List<Object> list;
also replace
@Overridepublic int getItemViewType(int position) { return studentList.get(position) != null ? VIEW_ITEM : VIEW_PROG;}
with
@Overridepublic int getItemViewType(int position) { return list.get(position) instanceof Student ? VIEW_ITEM : VIEW_PROG;}
for detect end of List you can using
@Overridepublic void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); // When went to the end of the list, load more posts if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (linearLayoutManager.findLastVisibleItemPosition() >= linearLayoutManager.getItemCount() - 1) { // Grow List } }}
Also for Add Loading Item. add this code in adapter
public void addLoadingView(){ list.add(new Object()); notifyDataSetChanged();}