Android 测验应用程序倒计时

Android Quiz App countdown

我的代码在下面给出,对于每个问题都有,即当倒计时结束时跳转到下一个问题并再次开始倒计时,我希望当倒计时结束时它应该跳转到结果页面..并且即使跳到下一题倒计时也不应该停止。

 @Override
protected void onResume()
{
    super.onResume();

    questionPlay = db.getRuleQuestionMode(mode);
    totalQuestion = questionPlay.size();

    mCountDown = new CountDownTimer(TIMEOUT, INTERVAL) {
        @Override
        public void onTick(long millisUntilFinished) {
            progressBar.setProgress(progressValue);
            progressValue++;

        }
        @Override
        public void onFinish() {
            mCountDown.cancel();

        }
    };
    showQuestion(index);
    db.close();
}


private void showQuestion(final int index) {

    if (index < totalQuestion) {
        thisQuestion++;
        txtQuestion.setText(String.format("%d/%d", thisQuestion, totalQuestion));
        progressBar.setProgress(0);
        progressValue = 0;


        txtView1.setText(questionPlay.get(index).getQus());
        btnA.setText(questionPlay.get(index).getAnswerA());
        btnB.setText(questionPlay.get(index).getAnswerB());
        btnC.setText(questionPlay.get(index).getAnswerC());
        btnD.setText(questionPlay.get(index).getAnswerD());
        mCountDown.start();

        Button btnca =(Button) findViewById(R.id.btnca);
        btnca.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StyleableToast st= new StyleableToast(getApplicationContext(),questionPlay.get(index).getCorrectAnswer(), Toast.LENGTH_SHORT);
                st.setBackgroundColor(Color.RED);
                st.setTextColor(Color.WHITE);
                st.setCornerRadius(3);
                st.show();
                score-=10;
            }
        });

    } else {
        Intent intent = new Intent(this, Done.class);
        Bundle dataSend = new Bundle();
        dataSend.putInt("SCORE", score);
        dataSend.putInt("TOTAL", totalQuestion);
        dataSend.putInt("CORRECT", correctAnswer);
        intent.putExtras(dataSend);
        startActivity(intent);
        finish();
    }

}

@Override
public void onClick(View v) {

    mCountDown.cancel();
    if (index < totalQuestion) {
        Button clickedButton = (Button) v;
        if (clickedButton.getText().equals(questionPlay.get(index).getCorrectAnswer())) {
            score += 10; // increase score
            correctAnswer++; //increase correct answer
            showQuestion(++index);



        } else {
            vibrator.vibrate(50);
            showQuestion(++index); // If choose right , just go to next question
        }
        txtScore.setText(String.format("%d", score));
        //clickedButton.setBackgroundColor(Color.YELLOW);;
    }
}

@Override
public void onStop() {
    if(mCountDown != null)
        mCountDown.cancel();
    super.onStop();
}

删除 showQuestion 方法中的 mCountDown.start();

在您的 onFinish 方法中,从那里调用您的结果页面