1
I’m developing a game. Usually in games there is a small clock that counts a few seconds backwards, kind of 10 to 0, and I would like to put one in my game.
How can I do that ?
PS: I’m using Android Studio
1
I’m developing a game. Usually in games there is a small clock that counts a few seconds backwards, kind of 10 to 0, and I would like to put one in my game.
How can I do that ?
PS: I’m using Android Studio
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();
Browser other questions tagged android android-activity
You are not signed in. Login or sign up in order to post.
Use a Countdowntimer. This reply may also help.
– ramaral