我目前正在开发黑莓应用。场景是当用户点击菜单项时,它将转到另一个页面。目前有3个类,MyApp,SecondPage和MyScreen。以下代码属于SecondPage。
从MyApp,我试图在用户点击MenuItem后将屏幕推送到SecondPage但是我无法这样做,因为它(SecondPage)正在扩展UiApplication我是对的吗?但如果我将其更改为扩展MainScreen,则无法进入pushScreen(_screen)。有什么建议吗?
谢谢, 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());
}
}
}
答案 0 :(得分:1)
您的屏幕需要从Screen继承,而不是从UiApplication继承。如果您查看UiApplication的文档,您会看到有一个静态方法getUiApplication()
,它会返回UiApplication的引用,以便推送屏幕(以及其他有用的任务)。
因此,您的代码不仅仅是pushScreen(_screen)
,而是UiApplication.getUiApplication().pushScreen(_screen)
。