简体   繁体   中英

Android setOnScrollListener on RecyclerView deprecated

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 ??

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.

Replace setOnScrollListener with addOnScrollListener

and it will work fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM