I implemented a listener class to detect the end of the scroll by referring to the link https://gist.github.com/marteinn/9427072
public class ResponsiveScrollView extends ScrollView { private OnBottomReachedListener listener; public ResponsiveScrollView(Context context) { super(context); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { View view = getChildAt(getChildCount()-1); int diff = view.getBottom()-(getHeight()+getScrollY()); if (diff == 0 && listener!= null) { listener.onBottomReached(this); } super.onScrollChanged(l, t, oldl, oldt); } public OnBottomReachedListener getBottomChangedListener() { return listener; } public void setBottomReachesListener(OnBottomReachedListener onBottomReachedListener) { this.listener = onBottomReachedListener; } public interface OnBottomReachedListener { public void onBottomReached(View view); } }
The listener is set to scrollView:
scrollView.setBottomReachesListener(new GenericScrollListerner(this));
My GenericScrollListerner class:
public class GenericScrollListerner implements ResponsiveScrollView.OnBottomReachedListener { private Context mContext; public GenericScrollListerner(Context context) { this.mContext = context; } @Override public void onBottomReached(View view) { Log.d("ScrollView","Scroll end"); String tag = (String) view.getTag(); Toast.makeText(mContext, "Scroll end with tag" +tag, Toast.LENGTH_SHORT).show(); }
}
My problem is that onBottomReached starts twice in most cases. How to deal with this problem?
source share