0

if I start the app in landscape mode, then it will use the landscape list item xml. but if I start it in portrait mode and rotate it to landscape mode, it will use the portrait list item xml for both configurations. I am using onConfigurationChanged to detect the orientation change, but I'm not sure how to tell it to use the correct xml file. I have two xml files with the same name, but one is for landscape. thanks.

mjpablo23
  • 681
  • 1
  • 7
  • 23

1 Answers1

0

If you Trying to achieve this you should have 2 folders for layouts one should be called

layout-land/*

other

layout-port/*

name your layouts the same

 File.xml 

than just inflate them OS takes care of rest.

Also see this Android layout folders: layout, layout-port, layout-land

specified android:configChanges="orientation" in the AndroidManifest.xml. In that case specify again setContentView() in the onConfigurationChanged() or remove that AndroidManifest.xml directive

If your want to just Keep using onconfigurationchanged() than just inflate appropriately.

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
Community
  • 1
  • 1
skryshtafovych
  • 572
  • 4
  • 16
  • ok thanks. I specified the two different folders, but I had to open the layout folder in the finder to see the two different folders. Then I had to remove "android:configChanges="orientation|screenSize|keyboardHidden" from the manifest file. – mjpablo23 Oct 17 '16 at 17:10
  • You can switch your view in left Top corner if your using Android Studio. If you setting the Layouts manually you can put them in the same res folder. – skryshtafovych Oct 17 '16 at 17:22