我已经实现了一个侦听器类来检测链接
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); } }
监听器设置为scrollView:
scrollView.setBottomReachesListener(new GenericScrollListerner(this));
我的GenericScrollListerner类:
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(); }
}
我的问题是onBottomReached在大多数情况下都会触发两次.如何处理这个问题???