I am using two xml layout file layoutPotrait.xml and layoutLandscape.xml.When device/emulator is in portrait mode i want to set the content view with layoutPortrait.xml file and when I will change the emulator to landscape mode I want to set content view with layoutLandscape.xml file. How can I achieve this?
Press Ctrl-F11 or Ctrl-F12 on your keyboard. See Offical manual for more commands and hotkeys.
To use different layouts for different orientations, place them in the appropriate folders: see Dev Guide on alternative resources (Screen Orientation section). For more info about changing the layout depending on orientation changes, see this article.
You don't need to know if the device changed. Just provide to layout files for all layouts you want to use in both ways.
If your Android device is in landscape mode and you are loading a layout the android system will look if this layout file exists in the /res/layout-land folder. If it does not exist in this folder it will load the layout from the normal /res/layout folder.
Just name the files the same and put the file that was called layoutPortrait.xml in your /res/layout folder and the layoutLandscape.xml in a /res/layout/land folder. If the folder does not exist create it.