如何开发多屏幕Blackberry应用程序?

时间:2009-11-04 09:57:33

标签: user-interface blackberry navigation

我需要开发一个应用程序,我可以使用前一个和下一个菜单项来更改屏幕。你能给我一个关于如何实现它的粗略想法吗?

由于

2 个答案:

答案 0 :(得分:5)

您可以将其实现为一系列屏幕并将其推入圆圈。但在推新之前不要忘记拉出当前屏幕。

这是应用程序将处理屏幕切换,它也将处理屏幕阵列。但是菜单放在屏幕上,所以我们必须在屏幕和应用程序类之间进行一些通信。

让我们有一些听众切换屏幕:

interface IBarrelListener {
    public void goPreviouse();

    public void goNext();
}

现在我们可以使用此监听器和相应的菜单实现屏幕:

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();
        };
    };
}

应用程序类本身:

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

答案 1 :(得分:0)

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

使用此功能显示另一个屏幕