Android setOnScrollListener on RecyclerView deprecated

AndroidAndroid RecyclerviewOnscrolllistener

Android Problem Overview


setOnScrollListener is deprecated. Reading the docs from here it tells to Use addOnScrollListener(OnScrollListener) and removeOnScrollListener(OnScrollListener).

What is the proper way to add and remove OnScrollListener?

Do i need to use removeOnScrollListner in onPause and set it up again using addOnScrollListener in onResume??

Android Solutions


Solution 1 - Android

addOnScrollListener(OnScrollListener) means you can add more than one listener to a RecyclerView.

removeOnScrollListener(OnScrollListener) means you can remove one of the listeners that attached to a specific RecyclerView. If the arg was set null, it equals to clearOnScrollListeners() method.

And, clearOnScrollListeners() let you remove all the listener from a RecyclerView.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKushal SharmaView Question on Stackoverflow
Solution 1 - AndroidMewXView Answer on Stackoverflow