I have a requirement for implementing pagination while scrolling up a RecyclerView. I am facing some issues as while adding content to the 0th position and notifying the adapter, recyclerview automatically scrolls to the top. Is there a way to disable that behaviour?
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
setFields(viewHolder, data);
if (position == 0 && getParentFragment().hasPrevious()) {
getParentFragment().callPreviousPage();
}
}
Where setFields(viewHolder, data);
method sets values to different fields.
if (position == 0 && getParentFragment().hasPrevious()) {
getParentFragment().callPreviousPage();
}
The above code is for calling web service when the position of the recycler view reaches 0 (pagination).
public synchronized void setList(final List<TournamentsData> list) {
this.list.addAll(0, list);
notifyDataSetChanged();
}
The above is the method for loading the data got from web service to the adapter.
Thank you so much in advance.