I have a Recyclerview
, and I need to display a countdown on every row.
Here is a similar question coutndown timers in listview It has a good solution ,
The Simple Solution Would Be:
Handler handler=new Handler();
handler.postDelayed(new UpdateTimerThread(holder),0);
public Class UpdateTimerThread implements Runnable{
Holder holder;
public UpdateTimerThread(Holder holder){
this.holder=holder;
}
@Override
public void run() {
lgetCreatedTime = lgetCreatedTime + 1000;
long diffSeconds;
long diffMinutes;
long diffHours;
diffSeconds = lgetCreatedTime / 1000 % 60;
diffMinutes = lgetCreatedTime / (60 * 1000) % 60;
diffHours = lgetCreatedTime / (60 * 60 * 1000) % 24;
holder.GameTimer.setText(String.format("%02d:%02d:%02d", diffHours, diffMinutes, diffSeconds));
handler.postDelayed(this,1000);
}
}
Note: 1.holder is the object of ViewHolder class
2.Create a class UpdateTimerThread implements Runnable
3.Convert Date and Time to long and store into lgetCreatedTime
4.Run Handler for every 1 Sec to tick the Time