Skip to content

Instantly share code, notes, and snippets.

@artworkad
Last active September 11, 2016 20:51
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 artworkad/ae6241d60282a54adfa22d28cddb48ae to your computer and use it in GitHub Desktop.
Save artworkad/ae6241d60282a54adfa22d28cddb48ae to your computer and use it in GitHub Desktop.
Implementation of RecyclerView.OnScrollListener
import android.support.v7.widget.RecyclerView;
/**
* You may set a scroll listener on a recycler view in order to be notified about scroll events.
*/
public class DefaultRecycleViewScrollListener extends RecyclerView.OnScrollListener {
OnScrollStateListener onScrollStateListener;
public DefaultRecycleViewScrollListener(OnScrollStateListener onScrollStateListener) {
this.onScrollStateListener = onScrollStateListener;
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (onScrollStateListener != null) {
onScrollStateListener.onScrollStateChanged(recyclerView, newState);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (onScrollStateListener != null) {
onScrollStateListener.onScrolled(dx, dy);
}
}
/**
* Listener methods.
*/
public interface OnScrollStateListener {
void onScrollStateChanged(RecyclerView recyclerView, int newState);
void onScrolled(int dx, int dy);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment