views:

37

answers:

1

Hi all, I have an activity which handles configuration changes. But now i have to change layout.I tried in onConfigurationChanged callback just to set again the layout and hoping will get the correct layout(land) but it's still showing the first layout for portrait view ( there two layout(same name) are placed in res/ layout and res/layout-land :)

if I delete android:configChanges="orientation", it works should be, but ı need to handle onConfigurationChanged. What should I do??

A: 

If you have your portrait layout main.xml in /res/layout and your landscape layout main.xml in /res/layout-land, and your onConfigurationChanged() looks like this:

    public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);                
            setContentView(R.layout.main);
    ...
    ...
    ...

    }

And in your Manifest you should have android:configChanges="keyboardHidden|orientation"

Then it should work fine, as this does in my app. Is this what you are doing?

ShadowGod
yes it works fine:)) thank you... I want to ask, why we should write keyboardHidden??
atasoyh
I think because on some devices when someone slides open the keyboard that also changes the orientation automatically.
ShadowGod