开发者

How to develop a multi screen Blackberry application?

开发者 https://www.devze.com 2022-12-10 16:44 出处:网络
I need to develop an application where I am able to change screens us开发者_高级运维ing menu items previous and next. Can u give me a rough idea about how to implement it?

I need to develop an application where I am able to change screens us开发者_高级运维ing menu items previous and next. Can u give me a rough idea about how to implement it?

Thanks


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


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

use this function to show another screen

0

精彩评论

暂无评论...
验证码 换一张
取 消