BlackBerry 将 UIApplication 与 MainScreen 结合使用
我正在尝试将浏览器字段添加到我的主屏幕上。目前,我有:
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);
}
});
}
}
除了其他 UI 元素之外,将浏览器插入主屏幕类的正确方法是什么?例如,添加(myBrowserField)?我不确定如何设置 BrowserFieldDemo 类来执行此操作,因为我需要为线程扩展 UIApplication...
public class LoginScreen extends MainScreen implements FieldChangeListener{}
谢谢!
更新:
我现在有以下内容:
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();
}
}
要启动浏览器,我调用(在登录屏幕中):
LoginBrowserField browser = new LoginBrowserField(url, this);
browser.start();
但是,我不确定上面的设置是否正确,因为浏览器需要很长时间才能出现在应用程序中,并且它无法正确解析我的 URL。你能看出有什么问题吗?
谢谢!
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 the 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要一个新线程在后台运行代码(即通过 HTTP 加载数据),您只需创建一个新的 Thread 对象并 start() 它 - 无需为此子类化 UiApplication。
另一方面,如果您需要安排一些代码在事件处理程序线程中运行(例如pushScreen),则可以使用
UiApplication.getUiApplication()
来获取UiApplication的实例,例如: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: