6
में पुस्तक के अंत के लिए कई बार फायरिंग

मैं स्क्रॉल दृश्य के अंत का पता लगाने के एक श्रोता वर्ग लिंक https://gist.github.com/marteinn/9427072scrollview

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 के लिए सेट है चर्चा करते हुए लागू किया है onScrollChanged कक्षा:

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(); 
} 

}

मेरी समस्या यह है कि BottomReached कई बार बार-बार गोलीबारी कर रहा है। इस समस्या को कैसे संभालें ???

उत्तर

1

अंत में उपयोग करने बनी रहती हैं, मैं एक ट्वीक के बिना एक जवाब मिल गया।

'NestedScrollView' के बजाय scrollview

public class ResponsiveScrollView extends NestedScrollView { 

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); 
    } 
} 

के साथ कस्टम स्क्रॉल दृश्य बढ़ाएँ ऊपर कोड काम करेंगे

4

यह ओवरक्रॉल के कारण होता है। कृपया scrollview XML घोषणा

android:overScrollMode="never" 

में निम्नलिखित पंक्ति जोड़ समस्या अभी भी उसके बाद निम्न ट्वीक

@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 && !stopTwice) { 
      stopTwice=true; 
      listener.onBottomReached(this); 
     }else{ 
      stopTwice=false; 
     } 
     super.onScrollChanged(l, t, oldl, oldt); 
    } 
+0

धन्यवाद। यह –

+0

काम करता है किसने काम किया? एक्सएमएल घोषणा या चिमटा? @remyathekkuvettil – Nizam

+0

tweak मेरे लिए काम किया @Nizam –

संबंधित मुद्दे