Ich habe einen geplanten Timer -mhandler handle aktualisiert manchmal falsche Textview
public void startTimer(long delay_minutes) {
final long delay = delay_minutes;
delay_countup = (double) delay;
//Start the scheduled time
departuretimer = new Timer();
departuretimer.scheduleAtFixedRate(new TimerTask() {
public void run() {
countup = 0.0 + delay_countup;
Log.d("hi","Values 0" + delay_countup + countup);
mHandler.obtainMessage(1).sendToTarget();
delay_countup = delay_countup + 0.5;
Log.d("hi","Values 1" + delay_countup);
}
}, 0, 30000);
}
public Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
Log.d("hi","Values 3" + countup);
delay_time.setText(String.valueOf(countup) + "min");
rootView.invalidate();
}
};
Die Protokolle immer korrekte Werte angezeigt werden, aber manchmal in der Benutzeroberfläche gibt es ein Problem. Das Problem ist, dass zum Beispiel -
delay_countup = 50.0
countup = 50.0
Textview updates as 50.0 //This is correct
Now,
delay_countup = 50.5
countup = 50.5
Textview updates as 0.5 //This is incorrect. I need 50.5
Dies passiert manchmal. Warum ist das?
EDIT: zu
Just added einloggt Handler ...
Values 0 = 34.5 34.5
Values 3 = 0.5
versuche 'delay_time.setText (countup +" min ");' in deinem 'mHandler' –
Ok, aber wie wirkt sich das aus? Ist String.valueOf das Problem verursacht? – Mark023
ich weiß nicht, ich gab nur einen Vorschlag. funktioniert es? –