在黑莓中切换页面/课程



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

从MyApp,我试图在用户点击菜单项后将屏幕推送到SecondPage,但我无法这样做,因为它(SecondPage)正在扩展UiApplication,我是对的吗?但如果我改变它扩展MainScreen,它不能推screen (_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());
        }
    }
}

你的屏幕需要从Screen继承,而不是从UiApplication。如果你看一下UiApplication的文档,你会看到有一个静态方法getUiApplication(),它会返回一个对UiApplication的引用,用于推送屏幕(在其他有用的任务中)。

所以,你的代码应该是UiApplication.getUiApplication().pushScreen(_screen),而不是pushScreen(_screen)

相关内容

  • 没有找到相关文章

最新更新