Last active
October 10, 2015 14:17
-
-
Save marteinn/3702758 to your computer and use it in GitHub Desktop.
InteractiveScrollView - Understanding when ScrollView has reached the bottom
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
| package se.marteinn.ui; | |
| import android.content.Context; | |
| import android.util.AttributeSet; | |
| import android.view.View; | |
| import android.widget.ScrollView; | |
| public class InteractiveScrollView extends ScrollView { | |
| OnBottomReachedListener onBottomReachedListener; | |
| public InteractiveScrollView(Context context, AttributeSet attrs, | |
| int defStyle) { | |
| super(context, attrs, defStyle); | |
| } | |
| public InteractiveScrollView(Context context, AttributeSet attrs) { | |
| super(context, attrs); | |
| } | |
| public InteractiveScrollView(Context context) { | |
| super(context); | |
| } | |
| @Override | |
| protected void onScrollChanged(int l, int t, int oldl, int oldt) { | |
| View view = (View) getChildAt(getChildCount()-1); | |
| int diff = (view.getBottom()-(getHeight()+getScrollY())); | |
| if( diff == 0 ){ | |
| // validate if we have a listener | |
| if( onBottomReachedListener != null ){ | |
| // trigger the listener | |
| onBottomReachedListener.onBottomReached(); | |
| } | |
| } | |
| super.onScrollChanged(l, t, oldl, oldt); | |
| } | |
| public OnBottomReachedListener getOnBottomReachedListener() { | |
| return onBottomReachedListener; | |
| } | |
| public void setOnBottomReachedListener( | |
| OnBottomReachedListener onBottomReachedListener) { | |
| this.onBottomReachedListener = onBottomReachedListener; | |
| } | |
| public interface OnBottomReachedListener{ | |
| public void onBottomReached(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment