开发者

How to reload layout?

开发者 https://www.devze.com 2023-03-01 23:42 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消