开发者

BlackBerry using UIApplication with MainScreen

I am trying to add a Browser Field onto my Main Screen. Currently, I have:

public class BrowserFieldDemo extends UiApplication {

private MainScreen _browserScreen;
private BrowserField _bf2;
private BrowserFieldConfig _bfConfig;

public BrowserFieldDemo(final String url) {
    _browserScreen = new MainScreen();
    _bfConfig = new BrowserFieldConfig();
    _bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,
            BrowserFieldConfig.NAVIGATION_MODE_POINTER);
    _bfConfig.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED,
            Boolean.TRUE);
    _bf2 = new BrowserField(_bfConfig);
    _browserScreen.add(_bf2);

    invokeLater(new Runnable() {
        public void run() {
            _bf2.requestContent(url);
            pushScreen(_browserScreen);
        }
    });
}
}

What is the correct way to insert th开发者_JAVA百科e browser to into Main Screen class, amongst other UI elements? For example, add(myBrowserField)? I am unsure how to set up the BrowserFieldDemo class to do this, because I need to extend UIApplication for the Thread...

public class LoginScreen extends MainScreen implements FieldChangeListener{}

Thanks!


Update:

I now have the following:

public class LoginBrowserField extends Thread {

    private LoginScreen loginScreen;
    private String url;

    public LoginBrowserField(String url, LoginScreen loginScreen) {
        this.loginScreen = loginScreen;
        this.url = url;
    }

    public void run() {
       synchronized (UiApplication.getEventLock()) {
        loginScreen.changeURL(url);
       }
    }
}

public class LoginScreen extends MainScreen implements FieldChangeListener {

     public void changeURL(final String url) {
        _bf2.requestContent(url);
        _bf2.setFocus();
     }

}

And to start the browser, I call (in LoginScreen):

LoginBrowserField browser = new LoginBrowserField(url, this);
browser.start();

However, I am not sure if my setup above is correct because it is taking a really long time for the browser to appear in the application, and it does not correctly resolve my URL. Can you see anything that is wrong?

Thanks!


If you need a new thread for running code in the background (i.e. loading data via HTTP) you can just create a new Thread object and start() it - no need to subclass UiApplication for this.

On the other hand, if you need to schedule some code to run in the event handler thread (such as pushScreen), you can use UiApplication.getUiApplication() to get an instance of a UiApplication, for example:

UiApplication.getUiApplication().invokeLater(new Runnable() {
    public void run() {
        pushScreen(_browserScreen);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜