Last active
September 11, 2016 20:51
-
-
Save artworkad/ae6241d60282a54adfa22d28cddb48ae to your computer and use it in GitHub Desktop.
Implementation of RecyclerView.OnScrollListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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