0

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

在 MyApp 中,我试图在用户单击 MenuItem 后将屏幕推送到 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());
        }
    }
}
4

1 回答 1

1

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

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

于 2011-08-01T12:45:38.067 回答