我在我的应用程序中使用倒数计时器,我需要以天数小时分钟和秒数显示即将到来的日期。我得到了天、小时、分钟和秒,但是当我将其设置为文本视图时,倒计时不会开始。下面是我的代码。
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;
}
这是输出
为什么倒计时没有开始?任何建议表示赞赏。