ksoichiro / Android-ObservableScrollView

Android library to observe scroll events on scrollable views.
http://ksoichiro.github.io/Android-ObservableScrollView/
Apache License 2.0
9.66k stars 2.06k forks source link

Didn't triger onScrollChanged when put this widget into a fragment #145

Closed saheru closed 9 years ago

saheru commented 9 years ago

I am using pulltonextlayout and this widget in project, and when I put it into a fragment, the scrolling will not triger onScrollChanged function, it's making me confused. btw,this is an awesome widget, I really like it. Thanks.

ksoichiro commented 9 years ago

Is that this library? I checked the sample app in this library, replaced ScrollView to ObservableScrollView in ScrollViewModel class, and it seems working.

ScrollViewModel.java:

public class ScrollViewModel extends PullToNextModel
    implements ObservableScrollViewCallbacks { // ADDED
    ...
    private ObservableScrollView scrollView; // CHANGED
    ...
    public void onBindView(int position, View v, PullToNextView pullToNextView) {
        ...
        scrollView = (ObservableScrollView) v.findViewById(R.id.scrollView); // CHANGED
        scrollView.setScrollViewCallbacks(this); // ADDED
        ...
    }
    ...
    // ADDED FOLLOWING CALLBACKS
    @Override
    public void onScrollChanged(int i, boolean b, boolean b1) {
        Log.e(TAG, "AOSV: onScrollChanged");
    }

    @Override
    public void onDownMotionEvent() {
        Log.e(TAG, "AOSV: onDownMotionEvent");
    }

    @Override
    public void onUpOrCancelMotionEvent(ScrollState scrollState) {
        Log.e(TAG, "AOSV: onUpOrCancelMotionEvent");
    }
}

fragment_scrollview.xml:

<!-- Just changed ScrollView to ObservableScrollView -->
<com.github.ksoichiro.android.observablescrollview.ObservableScrollView
  xmlns:android="http://schemas.android.com/apk/res/android"
...
</com.github.ksoichiro.android.observablescrollview.ObservableScrollView>

And I can get these logs:

06-11 00:03:42.504  19468-19468/? E/ScrollViewModel﹕ AOSV: onDownMotionEvent
06-11 00:03:42.555  19468-19468/? E/ScrollViewModel﹕ AOSV: onScrollChanged
06-11 00:03:42.572  19468-19468/? E/ScrollViewModel﹕ AOSV: onScrollChanged
06-11 00:03:42.589  19468-19468/? E/ScrollViewModel﹕ AOSV: onScrollChanged
06-11 00:03:42.606  19468-19468/? E/ScrollViewModel﹕ AOSV: onScrollChanged
06-11 00:03:42.621  19468-19468/? E/ScrollViewModel﹕ AOSV: onScrollChanged
06-11 00:03:42.623  19468-19468/? E/ScrollViewModel﹕ AOSV: onUpOrCancelMotionEvent
saheru commented 9 years ago

Thank you for help, I fix my code and it works :D, It's just I used this in pulltonextlayout and I didn't put the model in the right place:p

ksoichiro commented 9 years ago

Great :) Closing issue.