旋转的android手机时的EditText失去用户的输入 [英] EditText is losing users' input when rotating android phone
本文介绍了旋转的android手机时的EditText失去用户的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题
- 当用户键入到EDITTEXT (风景模式,或纵向)和 旋转手机的文本丢失。
- When a user types into the editText (landscape mode, or portrait) and rotates the phone the text is lost.
问
- 如何prevent的损失 文字?
- How can I prevent the loss of the text ?
底层code:
- 的onCreate() - > 的setContentView(myLayout) - > GET 引用UI部件与 findViewById()
- onConfigurationChanged() - >的setContentView(myLayout) - >获得与findViewById()引用的UI部件
- onCreate() -> setContentView(myLayout) -> get references to UI widgets with findViewById()
- onConfigurationChanged() -> setContentView(myLayout) -> get references to UI widgets with findViewById()
我的猜测是的setContentView()内onConfigurationChanged()会导致数据丢失。 我相信,我需要做的是从EditText上抓取数据之前出现这种情况。但如何?
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 ?
推荐答案
添加
安卓configChanges =定向
android:configChanges="orientation"
您在AndroidManifest.xml活动。这将旋转的方向,但要发生方向的改变不会改变。
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">
这篇关于旋转的android手机时的EditText失去用户的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文