0

If the user is putting data in edittext fields and orientation get changed, the onConfigChange method is called and new layout is populated,with empty edittext fields, i want to retain the data in edittext fields entered by user befor orientation change. Any kind of help will highly appreciated.

 protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            int orientation_default = getResources().getConfiguration().orientation;
            switch (orientation_default) {
            case Configuration.ORIENTATION_PORTRAIT: {
                setContentView(R.layout.registration);

                break;
            }
            case Configuration.ORIENTATION_LANDSCAPE: {
                setContentView(R.layout.registration_horizontal);
                break;
            }

            }
            findViewById(R.id.backtohomepage).setOnClickListener(this);
            findViewById(R.id.backtologinpage).setOnClickListener(this);
            findViewById(R.id.btn_notregyetsubmit).setOnClickListener(this);
            findViewById(R.id.termsandconditions_id).setOnClickListener(this);
            findViewById(R.id.btn_notregyetsubmit).setOnClickListener(this);
        }

        @Override
        public void onConfigurationChanged(Configuration newConfig) {

            super.onConfigurationChanged(newConfig);
            if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
                setContentView(R.layout.registration);
                findViewById(R.id.termsandconditions_id).setOnClickListener(this);
                findViewById(R.id.backtohomepage).setOnClickListener(this);
                findViewById(R.id.backtologinpage).setOnClickListener(this);
            } else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                setContentView(R.layout.registration_horizontal);
            }

            findViewById(R.id.backtologinpage).setOnClickListener(this);
            findViewById(R.id.btn_notregyetsubmit).setOnClickListener(this);
            findViewById(R.id.termsandconditions_id).setOnClickListener(this);
            findViewById(R.id.btn_notregyetsubmit).setOnClickListener(this);
        };
aalionline
  • 448
  • 2
  • 6
  • 21

2 Answers2

2

Put android:configChanges="orientation" for that activity node in the manifest.

EDIT: Check this question : Activity restart on rotation Android

Community
  • 1
  • 1
Dante
  • 1,104
  • 1
  • 10
  • 15
1
<activity
            android:name="com.Dashboard"
             android:configChanges="keyboardHidden|orientation"
            >
        </activity>

paste this in your manifest... http://developer.android.com/guide/topics/resources/runtime-changes.html .. go through this link..

NikhilReddy
  • 6,904
  • 11
  • 38
  • 58