2012-01-09 6 views
0

사용자가 모바일의 방향을 변경할 때마다 경고를 표시하려고합니다. 이 mouvement를 캡처하는 방법이 있습니까? 나는 Display.getOrientation();을 사용합니다. 하지만 항상 다른 방향으로 32를 반환합니다.제어 화면 방향 blackberry

답변

0

참고 :

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

} 
: 당신이 방향을 확인할 때 당신은 현명한 다른 실 거예요 다음 코드

시도 일 9800 시뮬레이터에서 슬라이더를 닫아야

3

오리엔테이션이 변경되면 sublayout()으로 전화가 걸립니다. 변수에 displaywidth을 저장할 수 있으며 값이 sublayout()에서 변경된 경우 방향이 변경되었음을 알 수 있습니다.

이와같이.

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