我正在尝试制作一个每分钟更改 UI 的应用程序,但我在 postAtTime 函数上遇到了很多困难,因为我无法触发它。我已经用 postDelay 尝试过它并且它有效,但 postAtTime 应该给我更多的精确度。
我获取当前时间并设置日历,然后在日期上添加一分钟并调用 postAtTime,但它不会触发。让我们看看你能不能帮助我。
private Runnable showMinute = new Runnable() {
public void run() {
calendar = Calendar.getInstance();
minute = calendar.get(Calendar.MINUTE);
minute = minute % 10;
switch (minute){
case 0: numero.setImageResource(R.drawable.b0);
break;
case 1: numero.setImageResource(R.drawable.b1);
break;
case 2: numero.setImageResource(R.drawable.b2);
break;
case 3: numero.setImageResource(R.drawable.b3);
break;
case 4: numero.setImageResource(R.drawable.b4);
break;
case 5: numero.setImageResource(R.drawable.b5);
break;
case 6: numero.setImageResource(R.drawable.b6);
break;
case 7: numero.setImageResource(R.drawable.b7);
break;
case 8: numero.setImageResource(R.drawable.b8);
break;
case 9: numero.setImageResource(R.drawable.b9);
break;
default:
break;
}
handler.removeCallbacks(mostrarHora);
calendar.add(Calendar.MINUTE, 1);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
handler.postAtTime(showMinute, calendar.getTimeInMillis());
}
};