Skip to content

Instantly share code, notes, and snippets.

@muhammad-naderi
Last active June 19, 2018 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muhammad-naderi/65f036048dff46557639e352561fb7ca to your computer and use it in GitHub Desktop.
Save muhammad-naderi/65f036048dff46557639e352561fb7ca to your computer and use it in GitHub Desktop.
simplesset endless scroll view listener ever
import android.support.v7.widget.RecyclerView;
public class EndlessScrollViewListener {
private LoadMoreListener listener;
public EndlessScrollViewListener(LoadMoreListener listener) {
this.listener = listener;
}
public RecyclerView.OnScrollListener getScrollListener() {
return new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
// Recycle view scrolling downwards...
// this if statement detects when user reaches the end of recyclerView, this is only time we should load more
if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
// remember "!" is the same as "== false"
// here we are now allowed to load more, but we need to be careful
if (listener != null) {
listener.loadMore();
}
}
}
}
};
}
public interface LoadMoreListener {
void loadMore();
}
}
@muhammad-naderi
Copy link
Author

muhammad-naderi commented Jun 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment