Click here to Skip to main content
14,325,129 members
Rate this:
Please Sign up or sign in to vote.
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 22:14pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100