I am using countdown timer in my application where i need to display upcoming date in days hours minutes and seconds left.I got the days,hours,minutes and seconds but when i set it to text view the countdown doesn't start.The below is my code.
Date date = new Date(2013,Integer.parseInt(datess.get(k).split("-")[1])-1,Integer.parseInt(datess.get(k).split("-")[0]),hours,mins,secs);
long dtMili = System.currentTimeMillis();
Date dateNow = new Date(dtMili);
remain = date.getTime() - dateNow.getTime();
MyCount counter = new MyCount(remain,1000);
counter.start();
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
tv3.setText("done");
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
tv3.setText(timeCalculate(millisUntilFinished/1000) + " Countdown");
}
}
public String timeCalculate(long ttime)
{
long daysuuu,hoursuuu, minutesuuu, secondsuuu;
String daysT = "", restT = "";
daysuuu = (Math.round(ttime) / 86400);
hoursuuu = (Math.round(ttime) / 3600) - (daysuuu * 24);
minutesuuu = (Math.round(ttime) / 60) - (daysuuu * 1440) - (hoursuuu * 60);
secondsuuu = Math.round(ttime) % 60;
if(daysuuu==1) daysT = String.format("%d day ", daysuuu);
if(daysuuu>1) daysT = String.format("%d days ", daysuuu);
restT = String.format("%02d:%02d:%02d", hoursuuu, minutesuuu, secondsuuu);
return daysT + restT;
}
This is the output
Why is the countdown not started? Any Suggestions are appreciated.