Android Development: How To Keep Text When Orientation Changes?
开发者_运维问答In my app I have a TextView that I use setText on after a certain action. But when the orientation changes the TextView's text is changed back to normal.
I have a similar problem with my app's file browser, for some reason it goes back to /sdcard/ when the orientation changes :/
Is there anything I can do to prevent loosing the TextView's text?
Store all your view's contents in onSaveInstanceState()
and reload it in onCreate()
. If you want to be funny and have all those values persist even after a system reboot, you could use SharedPreferences
, but saving the instance state is probably what you want here.
精彩评论