Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onConfigurationChanged-it's still showing the first layout

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??

like image 359
atasoyh Avatar asked Nov 30 '22 17:11

atasoyh


1 Answers

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?

like image 53
ShadowGod Avatar answered Dec 02 '22 07:12

ShadowGod