我在Android编程方面很新鲜,并试图找出countdowtimer。因为确定我的简单问答游戏的点数,我需要得到整数作为整数的秒数。我已经尝试了很多,但无法得到一个确切的解决方案。有人能帮帮我吗?
答案 0 :(得分:0)
试试这个:----
TextView textic = (TextView) findViewById(R.id.textView2);
CountDownTimer count = new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
textic.setText("Seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
textic.setText("Finished");
}
};
count.start();
有关详细信息,请查看CountDownTimer
答案 1 :(得分:0)
试试这种方式
CountDownTimer count = new CountDownTimer(1000000, 1000) {
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished / 1000) % 60;
int minutes = (int) ((millisUntilFinished / (1000 * 60)) % 60);
int hours = (int) (((millisUntilFinished / (1000 * 60)) % 60))%60;
textic.setText(hours +":"+minutes+":"+seconds);
}
public void onFinish() {
textic.setText("Finished");
}
};
count.start();