I'm trying to implement a skipping feature in my vertical recyclerview. When a user clicks a button, the recyclerView will scroll all the way to the bottom and trigger an API call. Right now to check if the user is at the bottom of the screen, I am using .addOnScrollListener
on my recyclerview.
mGridRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
//SCROLL_STATE_IDE prevents repeated calls from happening
// when near bottom of screen and slightly scroll up a bit
if(!mGridRecycler.canScrollVertically(1) && newState==RecyclerView.SCROLL_STATE_IDLE){
Log.d(TAG, "onScrollStateChanged: CALLED WTF");
mActivity.getNextPageGridView();
}
}
});
And to implement the skipping feature to the last item, I am using this method on a button:
mGridRecycler.scrollToPosition(mList.size() - 1);
It skips to the last item, however the API call is not triggered because the if-statement
is not called. Anyone know what I can make it work successfully?