How to develop a multi screen Blackberry applicati

2019-04-02 02:57发布

问题:

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