使用 onchronometerticklistener 的 if 语句
我正在尝试使用计时器创建一些基于时间的事件。下面的代码在计时器启动 5 秒后成功显示吐司,但我需要在 5/10/20 秒时显示吐司。
我尝试过使用 if (elapsedTime == 5000 ||elapsedTime == 10000 ) 但当我使用 == 时没有显示 toast。
有什么想法吗?
Chronometer.OnChronometerTickListener mChronoListener = new OnChronometerTickListener() { // listens to journey timer to initiate time based events
public void onChronometerTick(Chronometer arg0) {
long elapsedTime = SystemClock.elapsedRealtime() - arg0.getBase();
if (elapsedTime > 5000)
{
Toast.makeText(SafeDrive3Activity.this, "HOUR PASSED", Toast.LENGTH_LONG).show();
}
}
};
I'm trying to create some time based events using a chronometer. The code below is successfully displaying a toast after 5 seconds of chronometer being started however I need the toast to be displayed at 5/10/20 seconds.
I've tried using if (elapsedTime == 5000 ||elapsedTime == 10000 ) but no toast displays when I use ==.
Any ideas?
Chronometer.OnChronometerTickListener mChronoListener = new OnChronometerTickListener() { // listens to journey timer to initiate time based events
public void onChronometerTick(Chronometer arg0) {
long elapsedTime = SystemClock.elapsedRealtime() - arg0.getBase();
if (elapsedTime > 5000)
{
Toast.makeText(SafeDrive3Activity.this, "HOUR PASSED", Toast.LENGTH_LONG).show();
}
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的操作(如果您想此后每 10 秒保持一次):
Try something like this (if you want to keep it going every 10 seconds thereafter):