new CountDownTimer(400000, 100) {
public void onTick(long millisUntilFinished) {
Timer.setText((millisUntilFinished / 10000)+":"+(millisUntilFinished % 6000 / 100));
}
public void onFinish() {
Timer.setText("done!");
Intent intent = new Intent(ExamActivity.this,ResultActivity.class);
intent.putExtra("Score", score);
startActivity(intent);
finish();
}
}.start();
问题在于秒数如此之快。我试图实现40分钟的倒计时..上面是我的代码
答案 0 :(得分:3)
如果你想要40分钟试试这个:
new CountDownTimer(40*60*1000, 1000)
答案 1 :(得分:0)
访问CountDownTimer Documentation
new CountDownTimer(2400000, 1000) {
public void onTick(long millisUntilFinished) {
Timer.setText((millisUntilFinished / 10000)+":"+(millisUntilFinished % 6000 / 100));
}
public void onFinish() {
Timer.setText("done!");
Intent intent = new Intent(ExamActivity.this,ResultActivity.class);
intent.putExtra("Score", score);
startActivity(intent);
finish();
}
}.start();
答案 2 :(得分:0)
您计算的是以厘秒为单位,而不是毫秒。
尝试单独设置。
new CountDownTimer(40*60*1000, 1000) {
public void onTick(long millisUntilFinished) {
Timer.setText((millisUntilFinished / 10000)+":"+(millisUntilFinished % 6000 / 100));
}
public void onFinish() {
Timer.setText("done!");
Intent intent = new Intent(ExamActivity.this,ResultActivity.class);
intent.putExtra("Score", score);
startActivity(intent);
finish();
}
}.start();
答案 3 :(得分:0)
new CountDownTimer(40*60*1000, 1000) {
public void onTick(long millisUntilFinished) {
long minute= millisUntilFinished / (1000*60);
long second= (millisUntilFinished -(minute*60*1000))/1000;
Timer.setText(minute+":"+
second);
}
public void onFinish() {
Timer.setText("done!");
Intent intent = new Intent(ExamActivity.this,ResultActivity.class);
intent.putExtra("Score", score);
startActivity(intent);
finish();
}
}.start();
}