Answer the question
In order to leave comments, you need to log in
How to add CountDownTimer to RecyclerView items?
I need to show CountDown on every element. this is how i do it now
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
final PromosGS promos = promos_List.get(position);
CountDownTimer timer = new CountDownTimer(total_millis, 1000) {
@Override
public void onTick(long millisUntilFinished) {
long days = TimeUnit.MILLISECONDS.toDays(millisUntilFinished);
millisUntilFinished -= TimeUnit.DAYS.toMillis(days);
long hours = TimeUnit.MILLISECONDS.toHours(millisUntilFinished);
millisUntilFinished -= TimeUnit.HOURS.toMillis(hours);
long minutes = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished);
millisUntilFinished -= TimeUnit.MINUTES.toMillis(minutes);
long seconds = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished);
holder.promoDate.setText(days + "д" + " " + hours + "ч" + " " + minutes + "м" + " " + seconds + "с");
}
@Override
public void onFinish() {
holder.promoDate.setText("Завершен");
}
};
}
Answer the question
In order to leave comments, you need to log in
and why the timer should stop, someone stops it?
and I'm not sure that the CountDownTimer uses the thread pool, I believe that it starts a new thread when it is created. if I were you, I would have one handler that would tick and run only through the visible elements of the list and update the necessary data for them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question