04-23-2012 07:27 AM
hi,
In my app I have a RichMapField overlayed by a LabelField. I'm trying to delete the LabelField as soon as coordinates have been acquired by the GPS. The problem is I can change the text of the label, but not delete it. What am I doing wrong?
My code is below:
map = MapFactory.getInstance().generateRichMapField();
final LabelField locationNotAcquiredLabel = new LabelField("Acquiring location...");
map.add(locationNotAcquiredLabel, 150, 150);
Timer timer = new Timer();
final long start = System.currentTimeMillis();
timer.schedule(new TimerTask() {
public void run() {
Location location = LocationListenerImpl.getInstance().getLastLocation ();
if (location != null) {
long end = System.currentTimeMillis();
String elapsed = String.valueOf((end - start) / 1000); map.getAction().setCentreAndZoom(new MapPoint(location.getQualifiedCoordinates()), 10);
locationNotAcquiredLabel.setText("Elapsed: " + elapsed + " seconds"); // Works
map.delete(locationNotAcquiredLabel); // Doesn't work
map.getMapField().update();
this.cancel();
}
}
}, 0, 1000);
add(map);
04-26-2012 11:25 AM
Which BlackBerry Smartphone model and BlackBerry handheld software version are you testing on? You can find this under Options, About on the BlackBerry Smartphone.
04-27-2012 04:36 AM
It's the BB 9780 running OS 6.0 bundle 3106 (v6.0.0.723, Platform 6.6.0.248)
04-27-2012 10:16 AM
There is a very good article by Peter on background process...I hope this will help you.
04-30-2012 03:04 PM
This is caused by trying to update a screen from outside of the main event thread. This article explains it (Peter's does cover it as well, but he has a lot more info in there too).
Update a screen on the Main Event Thread