在 BlackBerry 中切换页面/类别

发布于 2024-11-27 09:26:20 字数 1462 浏览 0 评论 0原文

我目前正在开发一个黑莓应用程序。该场景是当用户单击菜单项时,它将转到另一个页面。目前有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

极度宠爱 2024-12-04 09:26:20

您的屏幕需要继承自 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 be UiApplication.getUiApplication().pushScreen(_screen).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文