开发者

How to use a countdown timer correctly in android

I have a return date(somewhere in near furture) stored within the application.

Now i need a find out current time of the android phone , then i can find out the amount of mins hours to countdown from . the below is what i have at the moment, when i create the below object i pass it PinnedCountdownTimer pct = new PinnedCountdownTimer((getTimeToReturn().getTime()-System.currentTimeMillis()),1000,countdownTv);

public class PinnedCountdownTimer extends CountDownTimer {

TextView tv;
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date resultdate ;
public PinnedCountdownTimer(long millisInFuture, long countDownInterval,TextView tv) {
    super(millisInFuture, countDownInterval);
    this.tv = tv;
}

@Override
public void onFinish() {
    tv.set开发者_开发技巧Text("get back to your car!");
}

@Override
public void onTick(long millisUntilFinished) {
    resultdate = new Date(millisUntilFinished);
    tv.setText("Left: " + sdf.format(resultdate) );
}

}

this does not work correctly.....do you guys have any idea?


According to the documentation, you need to call pct.start() from what I'm reading. Otherwise, I'm not an Android developer, but there's also the Timer class which is in regular Java, and looks to be available in Android as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜