Screen Orientation Control for Android

I have an activity in which there is a spinner. because for portrait and landscape mode I have a different layout, so I change the layout in the methodonConfigurationChanged

@Override
    public void onConfigurationChanged(Configuration conf) {
        super.onConfigurationChanged(conf);
        setContentView(R.layout.layout);
        initUI();
    } 

but the problem is that when I change the orientation, my counter is recreated, so if the spinner is open in portrait mode, it approaches in landscape mode. My requirement is: if it is open in any mode, it must be open after changing orientation. can you tell me how to handle this situation.

+5
source share
3 answers

try spinner performClick () method

0
source

Spinner,

<activity android:name=".Activity_name"
          android:configChanges="orientation|keyboardHidden">

, , , ,

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
            setContentView(R.layout.login_landscape);
        }
        else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            setContentView(R.layout.login);         
        }
    }

here.

0

, destroy , . destroy, . , , .

android:configChanges="orientation|keyboardHidden"
0

All Articles