首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓问答软件倒计时

安卓问答软件倒计时
EN

Stack Overflow用户
提问于 2017-03-03 06:14:05
回答 1查看 255关注 0票数 0

下面给出了我的代码,对于每一个问题,即当计数向下结束到下一个问题并再次开始计数时,我希望当倒计时结束时,它应该跳到结果page..and,即使在跳到下一个问题倒计时之后也不应该停止。

代码语言:javascript
复制
 @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();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-03 06:28:27

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

onFinish方法中,从那里调用结果页

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42571892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档