I have tried writing the following code
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(dy > 0){
//scrolling up
} else {
//scrolling down
int pastVisibleItems = linearLayoutManager.findFirstVisibleItemPosition();
if (pastVisibleItems == 0) {
Toast.makeText(getContext(),"Top most item",Toast.LENGTH_SHORT).show();
}
}
}
but it doesn't work. I have also tried using the android's SwipeRefreshLayout to do this since it does what I want which is able to detect when user has scroll to the topmost item. I decided to not use it because I can't seem to prevent the loading indicator from popping out (I don't want to see the loading indicator come out at all).
So, basically what I want to do is:
- check user scrolling
- is it the topmost item already?
- if yes, execute something, if no then nothing
Any idea how to accomplish this?
Thanks.
I have solved my question by myself. I used the code below instead
Then in the RecyclerView OnScrollListener
Replace your code with below code:
it works for me, if you get any error then comment.
You Can Do This easily use Code