Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I insert a countDownTimer inside ReclyerView by showing the value inside a textview. The countDownTimer Works fine when runs my Activity
My problem is that when I Scrolling through the ReclyerView and returning to the previous items ،The timer does not work properly and display incorrect numbers

What I have tried:

if (mListDiscountTab.get(holder.getAdapterPosition()).getmCountDownTimer() == null) {
                        mListDiscountTab.get(holder.getAdapterPosition()).setmCountDownTimer(new CountDownTimer((((mListDiscountTab.get(holder.getAdapterPosition()).getHour() * 60 * 60) + (mListDiscountTab.get(holder.getAdapterPosition()).getMinute() * 60) + (mListDiscountTab.get(holder.getAdapterPosition()).getSecond())) * 1000), 1000) {
                            public void onTick(long millisUntilFinished) {
                                Log.d("herePOU", holder.getAdapterPosition()+"");
                                long sec = (millisUntilFinished / 1000);
                                ((ViewHolderItem) holder).tv_item_timer_hour_home_discount.setText(NumberConverter.Number_English_to_Persian(sec / 3600));
                                ((ViewHolderItem) holder).tv_item_timer_minute_home_discount.setText(NumberConverter.Number_English_to_Persian(((sec % 3600) / 60)));
                                ((ViewHolderItem) holder).tv_item_timer_second_home_discount.setText(NumberConverter.Number_English_to_Persian((sec % 3600) % 60));

                            public void onFinish() {

Updated 16-Jun-19 23:14pm

1 solution

Then disable the timer, or "take evasive action", when you're scrolling.

It is not unusual to have "contention" when threads / events start overlapping; you then have to think about "synchronizing".

It's usual to log events (in say a text block) in order to determine their firing order and state.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900