How to develop a multi screen Blackberry application?

久未见 提交于 2019-12-21 06:08:10

问题


I need to develop an application where I am able to change screens using menu items previous and next. Can u give me a rough idea about how to implement it?

Thanks


回答1:


You can implement it as an array of screens and push them in circle. but don't forget to pull current screen before push new.

It's the application will handle screen switch and also it will handle the screen array. But menu is placed on the screen, so we have to make some communication between screen and application class.

Let's have some listener to switch screens:

interface IBarrelListener {
    public void goPreviouse();

    public void goNext();
}

Now we can implement screen with this listener and appropriate menu:

class ABarrelScreen extends MainScreen {
    IBarrelListener mBarrelListener;

    public ABarrelScreen(IBarrelListener barrelListener) {
        super();
        mBarrelListener = barrelListener;
    }

    protected void makeMenu(Menu menu, int instance) {
        super.makeMenu(menu, instance);
        menu.add(goPreviouseMenuItem);
        menu.add(goNextMenuItem);
    }

    MenuItem goPreviouseMenuItem = new MenuItem("go previouse", 0, 0) {
        public void run() {
            mBarrelListener.goPreviouse();
        };
    };

    MenuItem goNextMenuItem = new MenuItem("go next", 0, 0) {
        public void run() {
            mBarrelListener.goNext();
        };
    };
}

And application class itself:

public class ScrCircleApp extends UiApplication implements IBarrelListener {

    ABarrelScreen[] mScreens = generateScreens();
    int mCurrentScreen = 0;

    public ScrCircleApp() {
        pushScreen(mScreens[mCurrentScreen]);
    }

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

    private ABarrelScreen[] generateScreens() {
        ABarrelScreen[] screens = new ABarrelScreen[6];
        for (int i = 0; i < screens.length; i++) {
            screens[i] = new ABarrelScreen(this);
            screens[i].add(new LabelField("This is screen # "
                    + String.valueOf(i)));
        }
        return screens;
    }

    public void goNext() {
        popScreen(mScreens[mCurrentScreen]);
        mCurrentScreen++;
        if (mCurrentScreen >= mScreens.length)
            mCurrentScreen = 0;
        pushScreen(mScreens[mCurrentScreen]);
    }

    public void goPreviouse() {
        popScreen(mScreens[mCurrentScreen]);
        mCurrentScreen--;
        if (mCurrentScreen < 0)
            mCurrentScreen = mScreens.length - 1;
        pushScreen(mScreens[mCurrentScreen]);
    }
}

alt text http://img526.imageshack.us/img526/2372/screenbarrel.jpg




回答2:


getUiEngine().pushScreen(new MyNextScreen());

use this function to show another screen



来源:https://stackoverflow.com/questions/1672749/how-to-develop-a-multi-screen-blackberry-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!