黑莓:将应用限制为纵向模式

时间:2012-01-16 02:43:28

标签: blackberry

我在我的UiApplication类中尝试过这段代码,但是我得到了一个非法的statexception。

Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);

我不希望我的应用更改其方向。我希望它保持纵向模式。

编辑:

如何使用:

public class HelloWorld extends UiApplication {


    public static void main(String[] args){

        Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);


        HelloWorld theapp = new HelloWorld();
        theapp.enterEventDispatcher();

    }


    public HelloWorld(){

        pushScreen(new FeaturedScreen());

    }


}

2 个答案:

答案 0 :(得分:3)

DemoClass() 
{
     int direction = Display.DIRECTION_PORTRAIT;
     Ui.getUiEngineInstance().setAcceptableDirections(direction);
     pushScreen(new AppScreen(this));        
}
public static void main(String[] args) {
    DemoClass app1 = new DemoClass();                       
    app1.enterEventDispatcher();
}

答案 1 :(得分:1)

public class HelloWorld extends UiApplication {
   public static void main(String[] args){
       UiEngineInstance ui = Ui.getUiEngineInstance();//I have added this new line in your code
       ui.setAcceptableDirections(Display.DIRECTION_NORTH);
       HelloWorld theapp = new HelloWorld();
       theapp.enterEventDispatcher();
   }

   public HelloWorld(){
    pushScreen(new FeaturedScreen());
   }
}