2
我有一個天文臺。應該顯示時間。當我開始計時器的時間總是相同的,但它應該更新天文臺更新時間
呼叫:
Log.e("XXX","OnClick");
String[] array = clock.getText().toString().split(":");
int ms = (Integer.valueOf(array[0])*60 + Integer.valueOf(array[1]))*60000;
Log.e("XXX",String.valueOf(ms));
MyTimer counter = new MyTimer(ms, 1000, Timer.this,clock);
counter.start();
定時器:
public class MyTimer extends CountDownTimer {
private Context con;
private Chronometer clock;
public MyTimer(long millisInFuture, long countDownInterval, Context context, Chronometer clock) {
super(millisInFuture, countDownInterval);
this.con = context;
this.clock= clock;
// TODO Auto-generated constructor stub
}
@Override
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished/1000) % 60 ;
int minutes = (int) ((millisUntilFinished/(1000*60)) % 60);
int hours = (int) ((millisUntilFinished/(1000*60*60)) % 24);
clock.setText(String.format("%02d:%02d:%02d", hours,minutes,seconds));
Log.e("Timer", String.valueOf(millisUntilFinished));
}
的問題是,在天文鐘的時間總是相同。並且日誌(定時器) 也不會出現。難道是UI的刷新過快?
運行此代碼時'ms'的值是多少?它是'> 1000'嗎? – Caner
耶至少1分鐘= 60000ms – test123123
你確定你沒有得到異常的地方嗎?順便嘗試將整個代碼放入'try/catch'中,以便測試 – Caner