![](/img/trans.png)
[英]How to pass values for seconds in countdown timer , I am able to pass minutes but not seconds , it always start from 60
[英]how to use timer in minutes and seconds
我在Android应用程序中使用了计时器。
这就是我正在使用的
Timer t = new Timer();
//Set the schedule function and rate
t.scheduleAtFixedRate(new TimerTask() {
public void run()
{
//Called each time when 1000 milliseconds (1 second) (the period parameter)
runOnUiThread(new Runnable() {
public void run()
{
TextView tv = (TextView) findViewById(R.id.timer);
tv.setText(String.valueOf(time));
time += 1;
}
});
}
},
//Set how long before to start calling the TimerTask (in milliseconds)
0,
//Set the amount of time between each execution (in milliseconds)
1000);
在我的代码中,您可以看到只有seconds
,但是我想要分钟和00:01
秒。
所以,怎么做。 请帮我。
提前致谢。
一种获取所需String
的方法看起来像.-
int seconds = time % 60;
int minutes = time / 60;
String stringTime = String.format("%02d:%02d", minutes, seconds);
tv.setText(stringTime);
如果只需要在第二个Activity
显示结果,建议将时间值传递到args包中,并从活动中生成String
来显示它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.