4

I have this code:

recyclerView.setOnScrollChangeListener(this);

The problem is that android studio Call requires API level 23 (current min is 15)

I found similar questions but with no right answer.

how can I solve this error?

Zoe
  • 27,060
  • 21
  • 118
  • 148
RGS
  • 4,062
  • 4
  • 31
  • 67
  • 2
    You either only support devices v23 or later, or you find a different way of doing what you're trying to do. And without knowing what you're doing in/why you're using a scroll change listener we can't help you with that. – Gabe Sechan Feb 17 '17 at 19:24
  • 2
    Why don't you use an OnScrollListener insted? https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnScrollListener.html – amilcar-sr Feb 17 '17 at 19:24
  • thank you friends! – RGS Feb 17 '17 at 19:31
  • For `NestedScrollView` see https://stackoverflow.com/questions/49832043/nestedscrollview-setonscrollchangelistener-api-21. – CoolMind Oct 19 '21 at 15:20

1 Answers1

8

You could try implementing an onScrollListener instead. This is dependent on what you are implementing in your scroll events but if you are simply looking for something that is backward compatible to your min of 15 this would be the choice:

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);

        // onScrollStateChanged will be fire every time you scroll
        // Perform your operation here

        }
    }
Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
imaadhrizni
  • 428
  • 4
  • 11