2017-03-03 2 views
0

mein Code ist unten in der für jede Frage gibt es, dh wenn Countdown endet seinen Sprung zur nächsten Frage und Countdown startet wieder, ich will, dass wenn der Countdown endet sollte es auf die Ergebnisseite springen. .und sogar nach dem Sprung zur nächsten Frage Countdown sollte nicht aufhören.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(); 
} 
+0

Ich denke, das ist, was Sie lookng für: http://stackoverflow.com/questions/11532684/android-quiz-game-countdown-timer- for-each-qstion? rq = 1 –

+1

Ja, es hat mir geholfen, aber die Sache ist Countdown funktioniert auf die gleiche Weise wie ich erwartet hatte, aber nicht die Fortschrittsleiste –

+0

Also wollen Sie, dass wenn Fortschrittsbalken einen Wert von 5 am Ende hat von einer Frage, wenn die nächste Frage beginnt, wird Fortschrittsbalken wieder 5 haben? –

Antwort

1

mCountDown.start(); in Ihrer showQuestion Methode entfernen.

in Ihrem onFinish Verfahren gibt Ergebnisse Seite rufen von

+0

Was soll ich mit Fortschrittsbalken tun, so dass es fortgesetzt werden sollte, wenn ich zur nächsten Frage gehe –

+0

Ich sehe Sie Aufruf 'progressBar.setProgress (0);' in Ihrer 'showQuestion' Methode, einen Grund, warum Sie Fortschritt auf 0 wenn Hast du jemals die nächste Frage? –

+0

Nun, danke Sir, ich wusste, ich mache dumme Fehler –