2013-01-25 1 views
1

comment puis-je arrêter le compte à rebours, si je clique sur buttop en dehors de cette méthode? im en faisant un jeu qui avait une minuterie, quand je clique sur le bouton soumettre et si la réponse identifie que la réponse est correcte, le chronomètre s'arrêtera.Comment puis-je arrêter la minuterie à l'extérieur. comme si je clique sur un bouton en dehors de la méthode countdowntimer?

s'il vous plaît aidez-moi les gars. j'en ai besoin pour mon projet.

 public void timer1(){ 
    timer = (TextView)findViewById(R.id.timer); 

    final CountDownTimer Counter2 = new CountDownTimer(120000 , 1000) { 

     public void onTick(long millisUntilFinished) { 
      timer.setText(formatTime(millisUntilFinished)); 
     } 

     public void onFinish() { 
      timer.setText("GAME OVER"); 

     } 
     }; 


     Context mcontext=this; 

    final AlertDialog.Builder alert = new AlertDialog.Builder(
      mcontext); 

    alert.setTitle("LEVEL 1"); 
    alert.setPositiveButton("Start", 
      new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, 
        int which) { 
        dialog.cancel(); 
        Counter2.start(); 

        question(); 
       } 
      }); 
     alert.show(); 
} 
public void timer2(){ 
    timer = (TextView)findViewById(R.id.timer); 

    final CountDownTimer Counter1 = new CountDownTimer(120000 , 1000) { 

     public void onTick(long millisUntilFinished) { 
      timer.setText(formatTime(millisUntilFinished)); 
     } 

     public void onFinish() { 
      timer.setText("GAME OVER"); 

     } 
     }; 


     Context mcontext=this; 

    final AlertDialog.Builder alert = new AlertDialog.Builder(
      mcontext); 

    alert.setTitle("CORRECT"); 
    alert.setPositiveButton("OK", 
      new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, 
         int which) { 
        dialog.cancel(); 
        Counter1.start(); 

        question(); 
       } 
      }); 
     alert.show(); 
} 

}

Répondre

2

utilisation Counter2.cancel dans votre bouton onclick ...

+1

Je l'ai déjà fait mais ça ne s'est pas arrêté. –

1
timer.cancel(); 

ci-dessus chemin de code pour arrêter votre minuterie.

+0

l'annulation est erreur monsieur, où je vais mettre timer.cancel() ;? –

+0

sur votre bouton onclick ou si vous voulez arrêter votre minuterie. – duggu

+0

Échec de l'arrêt de sir –

Questions connexes