tags:

views:

66

answers:

2

I simply want to do:

if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
    setContentView(R.layout.search_portrait);
else
    setContentView(R.layout.search_landscape);

The problem is - getRequestedOrientation always returns -1.

Any suggestions?

A: 

Try adding android:screenOrientation="portrait" or android:screenOrientation="landscape" to your manifest for this activity. It will be the default orientation... that's because getRequestedOrientation "Return the current requested orientation of the activity. This will either be the orientation requested in its component's manifest, or the last requested orientation given to setRequestedOrientation(int).".

Cristian
+3  A: 

If you're just changing the layout, you should really think about putting your portrait layouts in /res/layout and your landscape layouts in /res/layout-land (with the same names) and Android will select the correct layout automatically.

Dave
kape123
I've not tried such exotic screen configs myself, but yes, I believe it does.
Dave
@kape123 yes, this will work.
alex