mobileDeveloper
mobileDeveloper

Reputation: 894

control screen orientation blackberry

I want to display an alert in every time when the user change the orientation of the mobile. There is a method to capture this mouvement? I use Display.getOrientation();. But it always returns 32 in different orientation.

Upvotes: 0

Views: 258

Answers (2)

Govindarao Kondala
Govindarao Kondala

Reputation: 2862

Note: when you check orientation you have to close SLIDER in 9800 simulator other wise it wont work

try following code :

public class checkOrientation 
{
     VerticalFieldManager manager;int ori;
      public checkOrientation()
    {
        ori=Display.getOrientation();
        manager=new VerticalFieldManager()
        {
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(Display.getWidth(),Display.getHeight());
                setExtent(Display.getWidth(),Display.getHeight());
                if(ori!=Display.getOrientation()){
                    UiApplication.getUiApplication().invokeLater(new Runnable() {
                        public void run() {
                            ori=Display.getOrientation();
                            Dialog.inform(""+Display.getOrientation());
                        }
                    });
                }
            }
        };
        add(manager);
    }

}

Upvotes: 0

rfsk2010
rfsk2010

Reputation: 8611

You get a call to sublayout() when orientation changes. You can save the displaywidth to a variable, and if the value has changed in sublayout() , you know the orientation has changed.

like this.

protected void sublayout(int width, int height) {
         if(Display.getWidth()==oldWidth)
         { 
             //no change
         }
         else
         {   
             // orientation changed
         }
            oldWidth = Display.getWidth();
            super.sublayout(width, height);
    }

Upvotes: 3

Related Questions