码:
Run Code Online (Sandbox Code Playgroud)public class SMH extends Activity { public void onCreate(Bundle b) { super.onCreate(b); setContentView(R.layout.main); TextView tv = (TextView) findViewById(R.id.tv); new CountDownTimer(10000, 2000) { public void onTick(long m) { long sec = m/1000+1; tv.append(sec+" seconds remain\n"); } public void onFinish() { tv.append("Done!"); } }.start(); }
输出:
10秒保持
8秒保持
6秒保持
4秒保持
完成!
问题:
如何让它显示" 2秒仍然 "?经过的时间确实是10秒,但最后一次onTick()从未发生过.如果我将第二个参数从2000更改为1000,那么这是输出:
10秒保持
9秒保持
8秒保持
7秒保持
6秒保持
5秒保持
4秒保持
3秒保持
2秒保持
完成!
所以你看,它似乎正在跳过最后一次onTick()调用.顺便说一句,XML文件基本上是默认的main.xml,TextView分配了id tv,文本设置为"".
我的一个问题是在android中改变计时器的格式.我有问题,天文钟显示其00:00格式的时间,我希望它以00:00:00格式出现.有谁知道答案?
我想用暂停和重启来做倒数计时器.现在我正在显示倒数计时器通过实现ontick()和onfinish().请帮帮我.这是倒数计时器的代码
final CountDownTimer Counter1 = new CountDownTimer(timervalue1 , 1000)
{
public void onTick(long millisUntilFinished)
{
System.out.println("onTick method!"(String.valueOf(millisUntilFinished/1000)));long s1=millisUntilFinished;
}
public void onFinish()
{
System.out.println("Finished!");
}
}
Run Code Online (Sandbox Code Playgroud)