在 BlackBerry 中切换页面/类别
我目前正在开发一个黑莓应用程序。该场景是当用户单击菜单项时,它将转到另一个页面。目前有 3 个类,MyApp、SecondPage 和 MyScreen。以下代码属于 SecondPage。
从 MyApp,我试图在用户单击 MenuItem 后将 Screen 推送到 SecondPage,但我无法这样做,因为它(SecondPage)正在扩展 UiApplication,对吗?但如果我将其更改为扩展MainScreen,则它无法pushScreen(_screen)。有什么建议吗?
谢谢, 亨德
class MyApp extends UiApplication{
//creating a member variable for the MainScreen
MainScreen _screen= new MainScreen();
//string variables to store the values of the XML document
String _node,_element;
Connection _connectionthread;
public static void main(String arg[]){
MyApp application = new MyApp();
//create a new instance of the application
//and start the application on the event thread
application.enterEventDispatcher();
}
public MyApp() {
_screen.setTitle("Agenda");//setting title
//_screen.add(new RichTextField("Requesting....."));
_screen.add(new SeparatorField());
pushScreen(_screen); // creating a screen
//creating a connection thread to run in the background
_connectionthread = new Connection();
_connectionthread.start();//starting the thread operation
}
public void updateField(String node, String element)
{
synchronized (UiApplication.getEventLock())
{
String title = "My App";
_screen.add(new RichTextField(/*node + " : " +*/ element + "\n" ));
if (node.equals(title))
{
_screen.add(new SeparatorField());
}
}
}
I am currently developing a blackberry app. the scenario is when a user clicks on a menu item, it will go to another page. Currently there are 3 classes, MyApp, SecondPage and MyScreen. the codes below belongs to SecondPage.
From MyApp, I am trying to pushScreen to SecondPage after the user clicks on a MenuItem but I'm unable to do so because it(SecondPage) is extending UiApplication am I right? but if I change it to extend MainScreen, it cant pushScreen(_screen). any suggestions please?
Thanks,
Hend
class MyApp extends UiApplication{
//creating a member variable for the MainScreen
MainScreen _screen= new MainScreen();
//string variables to store the values of the XML document
String _node,_element;
Connection _connectionthread;
public static void main(String arg[]){
MyApp application = new MyApp();
//create a new instance of the application
//and start the application on the event thread
application.enterEventDispatcher();
}
public MyApp() {
_screen.setTitle("Agenda");//setting title
//_screen.add(new RichTextField("Requesting....."));
_screen.add(new SeparatorField());
pushScreen(_screen); // creating a screen
//creating a connection thread to run in the background
_connectionthread = new Connection();
_connectionthread.start();//starting the thread operation
}
public void updateField(String node, String element)
{
synchronized (UiApplication.getEventLock())
{
String title = "My App";
_screen.add(new RichTextField(/*node + " : " +*/ element + "\n" ));
if (node.equals(title))
{
_screen.add(new SeparatorField());
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的屏幕需要继承自 Screen,而不是继承自 UiApplication。如果您查看 UiApplication 的文档,您会发现有一个静态方法
getUiApplication()
它将返回对 UiApplication 的引用,用于推送屏幕(以及其他有用的功能)任务)。因此,您的代码将不再是
pushScreen(_screen)
,而是UiApplication.getUiApplication().pushScreen(_screen)
。Your screens need to inherit from Screen, not from UiApplication. If you look at the docs for UiApplication, you see there is a static method
getUiApplication()
that will return you a reference to the UiApplication for purposes of pushing screens (among other useful tasks).So, instead of just
pushScreen(_screen)
your code would beUiApplication.getUiApplication().pushScreen(_screen)
.