-
Count down timer that shows in HH:MM:SS format
over 8 years ago
-
almost 8 years ago
Hello ,
You can use this method to show the time in HH:MM:SS format. You can also download the source code of Countdown timer in android from here
private void fn_countdown(long time){ countDownTimer = new CountDownTimer(time, sec) { @Override public void onTick(long millisUntilFinished) { onpause = millisUntilFinished; int seconds = (int) (millisUntilFinished / 1000) % 60; int minutes = (int) ((millisUntilFinished / (1000 * 60)) % 60); int hours = (int) ((millisUntilFinished / (1000 * 60 * 60)) % 24); String newtime = hours + ":" + minutes + ":" + seconds; if (newtime.equals("0:0:0")) { tv_time.setText("00:00:00"); } else if ((String.valueOf(hours).length() == 1) && (String.valueOf(minutes).length() == 1) && (String.valueOf(seconds).length() == 1)) { tv_time.setText("0" + hours + ":0" + minutes + ":0" + seconds); } else if ((String.valueOf(hours).length() == 1) && (String.valueOf(minutes).length() == 1)) { tv_time.setText("0" + hours + ":0" + minutes + ":" + seconds); } else if ((String.valueOf(hours).length() == 1) && (String.valueOf(seconds).length() == 1)) { tv_time.setText("0" + hours + ":" + minutes + ":0" + seconds); } else if ((String.valueOf(minutes).length() == 1) && (String.valueOf(seconds).length() == 1)) { tv_time.setText(hours + ":0" + minutes + ":0" + seconds); } else if (String.valueOf(hours).length() == 1) { tv_time.setText("0" + hours + ":" + minutes + ":" + seconds); } else if (String.valueOf(minutes).length() == 1) { tv_time.setText(hours + ":0" + minutes + ":" + seconds); } else if (String.valueOf(seconds).length() == 1) { tv_time.setText(hours + ":" + minutes + ":0" + seconds); } else { tv_time.setText(hours + ":" + minutes + ":" + seconds); } } @Override public void onFinish() { tv_time.setText(00 + ":" + 00 + ":" + 00); } }.start(); } }
-
1 Comment(s)