NestedScrollView setOnScrollChangeListener api 21

guisantogui picture guisantogui · Apr 14, 2018 · Viewed 6.9k times · Source

Hello folks I'm trying to handle an onScrolled event in my recyclerView, that's inside a NestedScrollView.

So far, I have found setOnScrollChangeListener, however this method is API 23, and I'm targeting API 21, any idea to handle this issue back in API 21?

Answer

NhatVM picture NhatVM · Apr 21, 2019

I think you are using setOnChangeScrollListener with View.OnScrollChangeListener. Please use NestedScrollView.OnScrollChangeListener like that:

 scvProduct.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
        @Override
        public void onScrollChange(NestedScrollView nestedScrollView,int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

            Log.e("ProductFragment","position button " + topPositionButton + " scrollY " + scrollY);
            if(scrollY > oldScrollY){
                Log.e("ProductFragment","down");
            }
            else{
                Log.e("ProductFragment","up");
            }
        }
    });

image compare NestedScrollview and View OnScrollChangeListener