在CountdownTimer上获取剩余时间,并将剩余时间用作评分机器人 [英] Get remaining time on CountdownTimer and use the remaining time as a score android
问题描述
所以我在这里有测验应用程序并有计时器。所以我想发生的事情例如我将计时器设置为15秒,如果用户在5秒钟内回答问题,我希望10秒钟的剩余时间变为10分,它将加到以前的分数上,而您的分数将保持不变回答问题。所以现在我有了这个...
So i have here Quiz App and have timer. So what i want to happen for example i have set the timer for 15 seconds and if the user answer the question in 5 seconds i want the 10 seconds ramaining become 10 points and it will add to previous score plus the score of you will get upon answering the questions. so for now i have this ...
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点
and here is the one for onclick. if the user answer correctly it will add 10points automatically
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上获取重排时间,并在答案正确时将其添加为分数。
I dont have any idea on how to get the remaianing time on CountdownTimer and add it as a score when the answer is correct. could anyone please help me please.
推荐答案
只需使用CountDownTimer的onTick上的millisUntilFinished
Just use millisUntilFinished from onTick of the CountDownTimer
奖金为 millisUntilFinished / 1000
PS我认为您最好使用较低的间隔大于1000,因此ProgressBar看起来会更平滑。
P.S I think you better use a lower interval than 1000, so the ProgressBar will seem smoother.
这篇关于在CountdownTimer上获取剩余时间,并将剩余时间用作评分机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!