views:

30

answers:

1

Hello All

In my blackberry application, I am doing something like below to update the label field for every second in run method of my thread class. But problem is application displays pre loader/hour glass for every update. I want to get rid of that hour glass and I want to see smooth update of the label field to be happened. How can I do that

public void run() {
while(true)
{
Thread.sleep(1000);
setRecordingTime(new Date().getTime());
}
}

private void setRecordingTime(long maxRecordTime) {
synchronized (UiApplication.getEventLock()) {

label.setText(getFormatted(maxRecordTime));

}
}

Thanks Sudhakar Chavali

+2  A: 

The hourglass should only show when the event lock is held for too long, so unless your getFormatted() method is quite slow I don't see a problem with the code above.

You may want to try the following code so that you add an item onto the existing event queue rather than explicitly grabbing the lock:

private void setRecordingTime(final long maxRecordTime) {
    UiApplication.getUiApplication().invokeLater(new Runnable() {
     public void run() {
      label.setText(getFormatted(maxRecordTime));
     }
    });
}
Marc Novakowski