I am new to eclipse and my timer in eclipse did not work properly, this is my java. code in the timer:
Button countDownButton2 = (Button) findViewById(R.id.countDown1);
countDownButton2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view){
CountDownTimer timer2 = new CountDownTimer(3000,1000){
@Override
public void onFinish() {
mTimeLabel1.setText("Times Up baby!");
}
@Override
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
mTimeLabel1.setText("" + minutes + ":"
+ String.format("%02d", seconds));
}
}.start();
}
});
Basically everything is running as I wish, however, I found that if I clicked the trigger button while it is counting, it will trigger another counting without stop the previous counting. This is very embarrassing, my friend suggest me to do "switch" if the button trigger again, and I am considering to add another actions to the same button which is stop the restart counting. Which one is more preferable?