title: Not getting orientation by using OrientationEventListener in android
body: <p>I need to detect an orientation of an device, for that I have written a code below. But I am unable get orientation.This is my oncreate() in MainActivity... 
  If i need to change anything please let me know</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
  
      mOrientationListener = new OrientationEventListener(getApplicationContext()) 
      {
          @Override
          public void onOrientationChanged(int orientation) 
          {
              if(orientation == 0)
              {
                  setContentView(R.layout.activity_main_portrait);
              }
              else
              {
                  setContentView(R.layout.activity_main_landscape);
              }
          }
      };
      if (mOrientationListener.canDetectOrientation()) 
      {          
          mOrientationListener.enable();
      }
  
      mImgPreview = (ImageView) findViewById(R.id.imgpreview);
      mVideoPreview = (ImageView) findViewById(R.id.videopreview);
      mAudioPreview = (ImageView) findViewById(R.id.audiopreview);
  
      /*-------Intent to view Image Gallery---------*/
      mImgPreview.setOnClickListener(new OnClickListener() 
      {
          @Override
          public void onClick(View v) 
          {
              Intent intent = new Intent(getApplicationContext(), ImageList.class);
              startActivity(intent);
          }
      });
  
      /*-------Intent to view Video Gallery---------*/
      mVideoPreview.setOnClickListener(new OnClickListener() 
      {
          @Override
          public void onClick(View v) 
          {
              Intent intent = new Intent(getApplicationContext(), Video.class);
              startActivity(intent);
          }
      });
  
      /*--------Intent to view Audio Gallery--------*/
      mAudioPreview.setOnClickListener(new OnClickListener() 
      {
  
          @Override
          public void onClick(View v) 
          {
              Intent intent = new Intent(getApplicationContext(), AudioPlayer.class);
              startActivity(intent);
          }
      });
  }
  </code></pre>
  
  <p>//Thanks in Advance</p>