所以我这里有测验应用程序和计时器。所以我想要发生什么,例如,我将计时器设置为 15 秒,如果用户在 5 秒内回答问题,我希望 10 秒的剩余时间变成 10 分,它将添加到之前的分数加上您将获得的分数回答问题。所以现在我有这个...
if(savedInstanceState!=null){
//saved instance state data
int exScore = savedInstanceState.getInt("score");
scoreText.setText("Score: "+exScore);
}
Timer = new CountDownTimer(15000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
tv_time.setText("" + millisUntilFinished / 1000);
int progress = (int) (millisUntilFinished / 150);
progressBar.setProgress(progress);
}
@Override
public void onFinish() {
progressBar.setProgress(0);
timeUp(context);
}
}.start();
这是 onclick 的一个。如果用户回答正确会自动加10分
public void onClick(View view) {
Button clicked = (Button) view;
int exScore = getScore();
if (clicked.getText().toString().equals(this.active_question.getAnswer()) ) {
if (this.questions.size() > 0) {
setQuestion(questions.poll());
scoreText.setText("Score: " + (exScore + 10))
} else {
CustomGameOver cdd = new CustomGameOver(PlayQuizActivity.this);
cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
cdd.show();
setHighScore();
Timer.cancel();
}
}
我不知道如何获取倒计时器的剩余时间并在答案正确时将其添加为分数。谁能帮帮我吗?
只需使用 CountDownTimer 的 onTick 中的 millisUntilFinished
奖金将是millisUntilFinished/1000
P.S 我认为你最好使用低于 1000 的间隔,这样 ProgressBar 看起来会更平滑。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)