简体   繁体   中英

RecyclerView with viewholder pattern temporarily prevent recycle on scroll

I have a recycler view showing a bunch of simple textviews, some textviews have a button beside them.

On button click, i show a progress bar beside that specific textview and show a simple media player progress.

Now, since i have a recycler when, when the user scrolls around when the mediaplayer is playing some sound and progressbar animating, scrolling back to that item will return it to its original formation.

Is there a way to mark an item as non-recycle temporarily? or do I have to set up some states around to return the recycled view back to its playing view??

No, you can't mark an item as non-recycle.All views in the adapter supposed to be recycled in order to get a better performance. I should have said much better performance. Because instead of creating 100 views or 1000 your adapter creates only 7~8 or more( depends on the screen size). Whenever the user scrolls around - Recycler does its job. In your case you need to keep track of all your items, like saving state of each item in some data structure and all that stuff.

or do I have to set up some states around to return the recycled view back to its playing view

My best bet would be for you to save the state of each item separately and once your viewholder is bound you set the player back to where it was. Make sure you recycle your items properly and bind them accordingly otherwise you'll end up with a mess of videos being set to the wrong times.

Given we're talking about video loading you might also want to control the RecyclerView 's scroll events and only start the videos once the user has stopped moving, this way you'll most likely improve your performance by not doing any unnecessary buffering.

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