7 messages in com.googlegroups.android-developersRe: How to update the UI from a timer
FromSent OnAttachments
Drew15 Feb 2008 06:51 
szeldon15 Feb 2008 07:42 
cirion15 Feb 2008 10:24 
MobileBen23 Mar 2008 16:19 
David23 Mar 2008 17:07 
Phision31 Mar 2008 09:40 
DanAtAndroid31 Mar 2008 10:01 
Subject:Re: How to update the UI from a timer
From:DanAtAndroid (danj@gmail.com)
Date:03/31/2008 10:01:05 AM
List:com.googlegroups.android-developers

The only way to do this is with a handler as mentioned a few times above already.

On Mar 31, 12:41 pm, Phision <kali@gmail.com> wrote:

I think I have the same problem. I want to update a progress bar at a regular interval of time. I am calling setProgress() each second but the progress bar will not redraw itself. I tried to call postInvalidate after setProgress and it works BUT only if I give a constant value to setProgress (for example setProgress(14)). When I give the value I want (which is one media player's position) it does not redraw itself I see that I shall try the approach, mentioned here - with handlers - but anyway is there anyone that can explain me why this happens? Here is my code of the timer:

public class KalinTask extends TimerTask { private TrackProgress p; private MediaPlayer mp;

public KalinTask(TrackProgress _p, MediaPlayer _mp){ p = _p; mp = _mp; p.setProgress(5); }

@Override public void run() { Log.e("upl", "Run: "+ p.getProgress()); p.setProgress((mp.getCurrentPosition()*100)/mp.getDuration()); p.postInvalidate(); }

}