简体   繁体   English

android中如何正确使用倒数计时器

[英]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.现在我需要找出 android 手机的当前时间,然后我可以找出倒计时的分钟小时数。 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);下面是我目前所拥有的,当我创建下面的 object 时,我将其传递给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.setText("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.根据文档,您需要从我正在阅读的内容中调用 pct.start() 。 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. 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM