我想在每分钟完成后显示一条祝酒消息。我正在使用倒数计时器并在文本视图中显示计时器。请帮我解决这个问题。以下是我的代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.track_me_mode);
counter = new MyCount (length,10);
counter.start();
}
});
public class MyCount extends CountDownTimer {
Context mContext;
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
public void onTick (long millisUntilFinished) {
timerView.setText ( formatTime(millisUntilFinished));
}
public void onFinish() {
}
}
public String formatTime(long millis) {
output = "";
long seconds = millis / 1000;
long minutes = seconds / 60;
long hours=minutes/ 60;
seconds = seconds % 60;
minutes = minutes % 60;
hours=hours%60;
String secondsD = String.valueOf(seconds);
String minutesD = String.valueOf(minutes);
String hoursD=String.valueOf(hours);
System.out.println(minutesD);
if (seconds < 10)
secondsD = "0" + seconds;
if (minutes < 10)
minutesD = "0" + minutes;
if (hours < 10)
hoursD = "0" + hours;
output = hoursD+" : "+minutesD + " : " + secondsD;
return output;
}
}