3

I want to stop activity refresh when I move on to portrait mood to landscape mood and I also want load file layout-land when it move to portrait to landscape mood without any refreshment the activity.

I use <activity android:name=".Login" android:configChanges="orientation|screenSize">

but,In this method when I move onto portrait to landscape mood ,It does not load the file from layout-land folder. what should I do for this? please someone help me.

2 Answers2

3

Call method setContentView(R.layout.main) in onConfigurationChanged()

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        ///in case you have some EditTexts , save their input before setting the new layout.
        emailForConfigChanges = emailTextBox.getText().toString().trim();
        passwordForConfigChanges = passwordTextBox.getText().toString().trim();

        setContentView(R.layout.main);

        //Now set the values back to the EditTexts .
    }

You just have to add this method to your activity as it handles all the orientation changes if you have declared "orientation" in your manifest.

EDIT : And if EditTexts lose their values on rotation, get their values before calling setContentView() in onConfigurationChanged(). See the edit above.

Yogesh Somani
  • 2,554
  • 3
  • 19
  • 34
  • when I rotate,It loads file from layout-land but it lose the values,I mean If I enter some values to text-field then it rotates, it lose the values.is there any solution? –  Oct 09 '12 at 14:33
  • See the edit.Just set the saved values in EditTexts after setContentView() is called. – Yogesh Somani Oct 09 '12 at 14:41
1

I handled this problem only by addding android:configChanges="keyboardHidden|orientation"

hope this will help you.

Naresh J
  • 1,959
  • 4
  • 24
  • 38
  • Thanks.it works but page refresh when it rotates.is there anyway to stop that? –  Oct 09 '12 at 14:42