问题描述:

I don't know how to explain better. I have this timer, and after it finish counting it should call another class (popup) and after that other function in the same class where the counter is.

public class MyCount extends CountDownTimer {

public MyCount(long millisInFuture, long countDownInterval) {

super(millisInFuture, countDownInterval);

}

public void onFinish() {

Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class);

i.putExtra("tacanOdgovor", tacanOdg);

startActivity(i);

mHandler.postDelayed(mLaunchTask,2200);

brojacPogresnihOdgovora++;

}

After first pass, my score is 2 instead of 1, then 6, the 14...This delayed method is simply the next question:

Runnable mLaunchTask = new Runnable() {

public void run() {

nextQuestion();

brojacVremena.start();

}

};

I call exactly the same method as the one in onFinish() when user answer wrong and it works fine.

MyCount brojacVremena = new MyCount(6000, 1000);

final OnClickListener clickListener = new OnClickListener() {

public void onClick(View v) {

 Answer ans = (Answer) v.getTag();

if (ans.isCorrect) {

brojacVremena.cancel();

brojacTacnihOdgovora = brojacTacnihOdgovora + 5;

Intent i = new Intent("rs.androidaplikacijekvizopstekulture.TACANODGOVOR");

startActivity(i);

mHandler.postDelayed(mLaunchTask,1200);

}

else{

brojacVremena.cancel();

brojacPogresnihOdgovora++;

Intent i = new Intent(getApplicationContext(), PogresanOdgovor.class);

i.putExtra("tacanOdgovor", tacanOdg);

startActivity(i);

mHandler.postDelayed(mLaunchTask,2200);

}

};

网友答案:

I found my error. I called my counter twice. Here:

nextQuestion(); 
brojacVremena.start();

and below in the very same nextQuestion method:

public void nextQuestion() {
brojacVremena.start();
.
.
.

I don't know how that happened.

相关阅读:
Top