Last active
June 19, 2018 16:11
-
-
Save muhammad-naderi/65f036048dff46557639e352561fb7ca to your computer and use it in GitHub Desktop.
simplesset endless scroll view listener ever
This file contains 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; | |
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
implementation