从推送的BlackBerry屏幕返回到父屏幕

时间:2011-01-19 15:23:18

标签: user-interface blackberry java-me mobile

我在Blackberry应用程序中有一个主菜单。当我进入菜单项并需要返回主菜单时,我想访问不同的屏幕。我该怎么办?

这是我尝试过但在按下后退按钮时遇到了运行时异常:

package com.stockmarket1;


import net.rim.device.api.system.Bitmap;
  import net.rim.device.api.ui.*;
  import net.rim.device.api.ui.container.*;
  import net.rim.device.api.ui.component.*;
  import net.rim.device.api.ui.decor.*;
  import net.rim.blackberry.api.push.PushApplication;

    public class StockMarket extends UiApplication implements FieldChangeListener   {
      public Screen _clientList;
      public Screen _comments;
      public Runnable _popRunnable;

    public static void main(String[] args)
    {
        StockMarket theApp = new StockMarket();
        theApp.enterEventDispatcher();
    }

    public StockMarket() {
        //Code for MainScreen
        final MainScreen baseScreen = new MainScreen();

        baseScreen.setTitle("Colombo Stock Exchange");
        ButtonField clientList = new ButtonField("View Client List", ButtonField.CONSUME_CLICK);
        clientList.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {
                pushScreen(_clientList);
                }
        });

        ButtonField comments= new ButtonField("View Comments", ButtonField.CONSUME_CLICK);
        comments.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {
                pushScreen(_comments);
                }
        });     
        Bitmap bitmap = Bitmap.getBitmapResource("logo1.png");
        BitmapField logo = new BitmapField(bitmap, BitmapField.FIELD_HCENTER);
        LabelField newLine = new LabelField("\n");

        baseScreen.add(logo);
        baseScreen.add(newLine);
        baseScreen.add(clientList);
        baseScreen.add(comments);


        //Code for _comments
        _comments = new FullScreen();
        _comments.setBackground(BackgroundFactory.createSolidBackground(Color.LIGHTCYAN));
        LabelField title = new LabelField("Comments",LabelField.FIELD_HCENTER);


        LabelField comment = new LabelField("Type");
        RichTextField rtfComment = new RichTextField();

        _comments.add(title);
        _comments.add(comment);
        _comments.add(rtfComment);

        //Code for _clientList
        _clientList = new FullScreen();
        _clientList.setBackground(BackgroundFactory.createSolidBackground(Color.LIGHTBLUE));
        LabelField clientTitle = new LabelField("Listed Companies\n\n", LabelField.FIELD_HCENTER);
        LabelField line = new LabelField("__", LabelField.USE_ALL_HEIGHT);

        ButtonField closeClient = new ButtonField("Close", ButtonField.CONSUME_CLICK);


        closeClient.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {
                pushScreen(baseScreen);
            }
        });

        _clientList.add(clientTitle);
        _clientList.add(line);

        //Events
        pushScreen(baseScreen);
    }

    public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub

    }
}

1 个答案:

答案 0 :(得分:1)

您关闭的代码'按钮是一个问题,但我想你说你在点击'后面时会遇到RuntimeException。设备上的按钮,我认为有不同的原因。

您应该只弹出当前屏幕,而不是将菜单屏幕推到屏幕堆栈上。这将返回到之前显示的菜单屏幕:

    closeClient.setChangeListener(new FieldChangeListener() {
        public void fieldChanged(Field field, int context) {
            // previous code:
            // pushScreen(baseScreen);
            // correct code:
            popScreen(_clientList);
        }
    });