How to fix the alignment for the vertical and portrait screen in BlackBerry?

advertisements

I want to do application which will not change UI even if screen is changed to portrait or landscape direction. How to do that?


I have made a static method in one of my library classes:

public static void disableOrientationChange()
{
    // force app to use only portrait mode
    int directions = Display.DIRECTION_NORTH;
    UiEngineInstance engineInstance = Ui.getUiEngineInstance();
    if (engineInstance != null)
    {
        engineInstance.setAcceptableDirections(directions);
    }
}

The trick is that this code only works for screens created after running it. So you must run the code BEFORE you show your first screen.

I call this method from my Application.main(String args) method, just before the call to enterEventDispatcher().

public static void main(String[] args)
{
    MyApp app = new MyApp();

    /*
     * BlackBerry OS 5.0.0
     * Disable screen orientation changes
     */
    ScreenUtils.disableOrientationChange();

    // enters the event processing loop thread if required
    if (!app.isHandlingEvents())
    {
        app.enterEventDispatcher();
    }
}