旋转的android手机时的EditText失去用户的输入机时、用户、android、EditText

由网友(空叹)分享简介:问题 当用户键入到EDITTEXT(风景模式,或纵向)和旋转手机的文本丢失。When a user types into the editText(landscape mode, or portrait) androtates the phone the text is lost.问 如何prevent的损失...

问题

当用户键入到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">
阅读全文

相关推荐

最新文章