Friday, June 29, 2012

[android-developers] Re: How to prevent the layout from getting reset when the screen orientation changes?

As someone in your other thread already mentioned: you need to keep track of these layout changes you do and save this information in the onSaveInstanceState method. You could save a boolean value for example that indicates that "Button 2" has been added. In onCreate you need to read the savedInstanceState Bundle and check whether that "Button 2" flag is present. If that is the case you have to re-create Button 2 then.

Some pseudo code:

onSaveInstanceState(Bundle outState) {
    outState.putBoolean("button2", true);
}

onCreate(Bundle savedInstanceState) {
    if(savedInstanceState != null) {
        if(savedInstanceState.getBoolean("button2")) {
             // Add button 2 to your layout
        }
    }
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate