开发者

EditText is losing users' input when rotating android phone

PROBLEM

  • When a user types into the editText (landscape mode, or portrait) and rotates the phone the text is lost.

QUESTION

  • How can I prevent the loss of the text ?

underlying code:

  • onCreate() -> setContentView(myLayout) -> get references to UI widgets with findViewById()
  • onConfigurationChanged() -> setContentView(myLayou开发者_运维技巧t) -> get references to UI widgets with findViewById()

my guess is that the setContentView() within onConfigurationChanged() causes the data loss. What I believe I need to do is grab the data from the EditText before this happens. But how ?


add

android:configChanges="orientation"

to your activity in the androidmanifest.xml. This will rotate the orientation but make no changes occur on orientation change.

<activity android:name=".activityname"
android:label="@string/app_name"
android:configChanges="orientation">


I'm not positive, but almost, that when the orientation changes the activity is completely recreated is it not? You would have to use bundle to save instance states and such, check out this discussion about roughly the same topic and I'm sure you'll figure it out! Cheers!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜