Answer the question
In order to leave comments, you need to log in
How to check if the recyclerView has reached the top of the list?
In my application I have a list created on the basis of recyclerView which has its own adapter. This adapter is filled with data that it receives from the server, let's take a list of messages for example. Currently, I'm trying to add new items to the list when reaching the bottom or top level of the list (similar to the Gmail message list). I read about the library that is used in Gmail, but I did not understand how it can be used in my situation. Now I managed to add list elements when the bottom border of the list is reached, and everything seems to be working fine. But I won't be able to do the same using the experience I've gained from reaching the bottom of the list. First I created an interface:
public interface OnBottomReachedListener {
void onBottomReached(int position);
}
void setOnBottomReachedListener(OnBottomReachedListener onBottomReachedListener) {
this.onBottomReachedListener = onBottomReachedListener;
}
if (position == getItemCount() - 1) {
onBottomReachedListener.onBottomReached(position);
}
((ListAdapter) adapter).setOnBottomReachedListener(new OnBottomReachedListener() {
@Override
public void onBottomReached(int position) {
getMessages(type, a_token, offset + 50);
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question