Regressive Clock [closed]

1

I'm developing a game. Usually in games there is a small clock that counts a few seconds to the contrary, type 10 to 0, and I would like to put one in my game.

How can I do this?

PS: I'm using Android Studio

    
asked by anonymous 06.02.2017 / 23:30

1 answer

1

Use the class CountDownTimer .

new CountDownTimer(tempo, 1000) {

        public void onTick(long millisUntilFinished) {
            long millis = millisUntilFinished;
            String hms = (TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis))) + ":" + (TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));

            // o código abaixo mostra quantos segundos faltam em uma textview
            suaTextView.setTitle(hms);
            tempo = millis;
        }

        public void onFinish() {
            suaTextview.setTitle("00:00");
            // executar uma ação quando o tempo acabar
        }
    }.start();
    
07.02.2017 / 01:08