Timer Android counter

Viewed 2114

I'm trying to implement a Timer counter, but all that I see is CountDown and I don't want to count down time, I just want start from 00:00 and every second sum one second until 60:00, I've been trying to implement this :

1.-Android timer? How? - Answer

2.- Chronometer

And they didn't help me at all.. can you guide me how to start time from 00:00 and end in 60:00?

Answer here :

As Usama Zafar put his answer, I updated the code to control this CountDownTimer in case you'll need it...

I created

CountDownTimer cdtTimer;

Then the method I have to startTimer() that starts to count the time it's like this :

private void StartTimer(){
    final long EndTime   = 3600;
    cdtTimer = new CountDownTimer(EndTime*1000, 1000) {
        public void onTick(long millisUntilFinished) {
            long secondUntilFinished = (long) (millisUntilFinished/1000);
            long secondsPassed = (EndTime - secondUntilFinished);
            long minutesPassed = (long) (secondsPassed/60);
            secondsPassed = secondsPassed%60;
            tvCounterTimer.setText(String.format("%02d", minutesPassed) + ":" + String.format("%02d", secondsPassed));
        }

        public void onFinish() {
            tvCounterTimer.setText("done!");
        }
    }.start();
}

Then wherever I want to cancel this CountDownTimer I simply do

cdtTimer.cancel();
1 Answers
Related