0

I am turning a view, which is the same but horizontally. which contains many variables of type TextView, progressbar, imageview, etc .. but I can not load the variables when rotated.

I tried to do:

android: configChanges = "keyboardHidden | orientation | ScreenSize | ScreenLayout"

I find methods that can save my customized classes, my progressbar, my views "My nothing."

https://i.stack.imgur.com/hYtuo.png

When there anyway to load a landscape (another layout (with the same id's)) of not losing data?

To change the layout I use:

http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged(android.content.res.Configuration)

Update Code 10/04/2015 (0:45 AM)

My rotation :

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

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.activity_1);

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.activity_2);
    }
   }

Oncreate

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                setContentView(R.layout.activity_1);

        } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
                           setContentView(R.layout.activity_2);
 }

References : Saving Android Activity state using Save Instance State Can't sabe all objects exits of an activity. "I think"

Community
  • 1
  • 1
Calimbo
  • 81
  • 1
  • 3
  • 13

2 Answers2

1

The easiest way would be to not specify orientation for the configChanges. Correspondingly, you will not need to override onConfigurationChanged -- you can simply load the layout in onCreate and state should for the most part be preserved. If needed state data can be stored in onSaveInstanceState (and restored in onCreate).

jor
  • 41
  • 3
  • mainly load another layout, with the same ids in landscape. the onSaveInstanceState can save (progressbar? or custom objects? or views? configuations, etc.) – Calimbo Apr 09 '15 at 23:04
  • If you have a layout with the same id (containing corresponding views) defined under layout-land it will load that for landscape (otherwise it will use the same layout). View data should be automatically transferred, but you can do custom stuff using onSaveInstanceState if needed. – jor Apr 09 '15 at 23:36
0

can you provide your code?
One possible issue is that you might be loading your layout file in onResume instead of onCreate. You need to create the layout in onCreate so the savedInstanceState info gets "injected" back into your app. But again, please provide codes :)

My guess is that elements of your layout don't have the same ID. Also, why don't you just have an XML for certain specifications - one for landscape and one for portrait? I bet Android would behave better if you did that instead of a different name for a different configuration

Bruno Carrier
  • 530
  • 5
  • 8