How to reload layout?
My app lets users change the text and visibility on some TextViews. I want to offer a button that will undo all changes and return the layout to it's original开发者_StackOverflow settings.
If you turn the phone from portrait to landscape, it does just that... but how do I trigger it from a button?
You could invalidate the base View
or call Activity.setContentView
If you turn the phone from portrait to landscape, it does just that... but how do I trigger it from a button?
The recreate
method of the Activity
class seems to do just that. Quote from the docs:
Cause this Activity to be recreated with a new instance. This results in essentially the same flow as when the Activity is created due to a configuration change -- the current instance will go through its lifecycle to onDestroy() and a new instance then created after it.
An example "configuration change" mentioned above is orientation change, i.e. switching from landscape to portrait or the other way around.
精彩评论