Blackberry - LabelField Dynamic Update Issues
I am trying to develop a BlackBerry app for a Storm2. I am facing a problem when trying to update a LabelField from a different instance of the app.
The program is working fine without updating this LabelField, but when I tried to add the code to update开发者_如何学Python the text, it becomes unresponsive after the "settext" line.
Am I missing something?
public class AgentTrackerScreen extends MainScreen
{
public static LabelField _outputText;
...
}
public class BtService implements Runnable
{
...
public void run()
{
AgentTrackerScreen._outputtext.settext(
"Something: " + btListener.vecDevices.size());
}
...
}
You must make all user interface modifications on the event thread, or else lock the user interface before doing it. See BlackBerry UI Threading Basics for details.
(BTW, this is a common requirement in many user interface systems. Swing in Java SE has this requirement. So does WPF on Windows.)
Use either:
- invokeAndWait(Runnable r)
- invokeLater(Runnable r)
- synchronize on UiApplication.getEventLock()
精彩评论