2011-08-01 33 views
0

我目前正在开发黑莓应用程序。该场景是当用户点击菜单项时,它将转到另一个页面。目前有3个类,MyApp,SecondPage和MyScreen。下面的代码属于第二页。在黑莓切换页面/类

从MyApp,我想在用户点击一个MenuItem后推屏幕到第二页,但我无法这样做,因为它(第二页)扩展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()); 
     } 
    } 
} 

回答

1

你的屏幕需要继承屏幕,而不是从UIApplication的。如果您查看UiApplication的文档,您会看到有一个静态方法getUiApplication(),它会返回您为推送屏幕(以及其他有用任务)而引用的UiApplication。

因此,而不是只是pushScreen(_screen)您的代码将是UiApplication.getUiApplication().pushScreen(_screen)