我有以下代码应该每秒更改一次文本视图,但仅每 2 秒甚至每 4 秒更改一次:
final TextView tv = (TextView) findViewById(R.id.textView1);
new CountDownTimer(remain, 1000)
{
@Override
public void onFinish()
{
tv.setText("Done");
}
@Override
public void onTick(long millisUntilFinished)
{
tv.setText(timeCalculate(millisUntilFinished / 1000));
}
}.start();
public String timeCalculate(long ttime)
{
long days, hours, minutes, seconds;
String daysT = "", hoursT = "", minutesT = "", secondsT = "";
days = (Math.round(ttime) / 86400);
hours = (Math.round(ttime) / 3600) - (days * 24);
minutes = (Math.round(ttime) / 60) - (days * 1440) - (hours * 60);
seconds = Math.round(ttime) % 60;
if (days == 1)
daysT = String.format(Locale.getDefault(), "%d day", days);
if (days > 1 || days == 0)
daysT = String.format(Locale.getDefault(), "%d days", days);
if (hours == 1)
hoursT = String.format(Locale.getDefault(), ", %d hour", hours);
if (hours > 1 || hours == 0)
hoursT = String.format(Locale.getDefault(), ", %d hours", hours);
if (minutes == 1)
minutesT = String.format(Locale.getDefault(), ", %d minute", minutes);
if (minutes > 1 || minutes == 0)
minutesT = String.format(Locale.getDefault(), ", %d minutes", minutes);
if (seconds == 1)
secondsT = String.format(Locale.getDefault(), " %d second", seconds);
if (seconds > 1 || seconds == 0)
secondsT = String.format(Locale.getDefault(), " %d seconds", seconds);
return daysT + hoursT + minutesT + secondsT + " remaining";
}
我究竟做错了什么?