Layout-land XML files do not work with onConfigurationChanged call back

I have different layouts for portrait and landscape mode, and I also need to override the callback onConfigurationChanged(). But the problem is that when I change the orientation of the phone to the landscape, my landscape layout does not work.

Can someone tell me this is a call problem onConfigurationChangedor something else causing this?

Any help would be greatly appreciated.

+3
source share
2 answers

i also need to override the onConfigurationChanged () callback

Why?

but the problem is that when I change the orientation of the phone to landscape, my landscape layout does not work.

, " " , . , , .

, android:configChanges="keyboardHidden|orientation". , , .

+10

, ...

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    int ot = getResources().getConfiguration().orientation;
    switch (ot) {
    case Configuration.ORIENTATION_LANDSCAPE:
        setContentView(R.layout.main_land);
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        setContentView(R.layout.main);
        break;
    }
    Toast.makeText(this, "Helloo", Toast.LENGTH_SHORT).show();
}
enter code here
@Override
public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    super.onConfigurationChanged(newConfig);

    int ot = getResources().getConfiguration().orientation;
    switch (ot) {
    case Configuration.ORIENTATION_LANDSCAPE:
        setContentView(R.layout.main_land);
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        setContentView(R.layout.main);
        break;
    }
}

@Override
public Object onRetainNonConfigurationInstance() {
    // TODO Auto-generated method stub
    return super.onRetainNonConfigurationInstance();
}

}

. : configChanges = "keyboardHidden | "

+2

All Articles