Countdown timer in recyclerview not working properly

廉价感情. 提交于 2019-12-05 18:25:27

The issue is that on every onBindViewHolder call you are creating a new CountDownTimer and updating that ViewHolder. So after a couple of scrolls, multiple CountDownTimer will try to update the same ViewHolder.

Create only one CountDownTimer per ViewHolder. To do that, cancel the CountDownTimer by calling the .cancel(); on it before setting a new CountDownTimer on the ViewHolder.

In order to get access to the CountDownTimer already set on a ViewHolder, create it on onCreateViewHolder and put it inside MyViewHolder as a field.

Have a public method on MyViewHolder called say update which does all the procedure you have written in onBindViewHolder and simple call update in onBindViewHolder of the Adapter. (cleaner code too :) )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!