問(wèn)題描述
我遇到了 EditText 控件的問(wèn)題.這個(gè)問(wèn)題只發(fā)生在這個(gè)特定的活動(dòng)上,沒(méi)有其他帶有 EditTexts 的活動(dòng).我已刪除此 EditText 的所有 setText 調(diào)用,但問(wèn)題仍然存在.
I'm having an issue with an EditText control. This issue is only happening on this particular Activity and no other Activities with EditTexts. I have removed all setText calls for this EditText and the problem still persists.
我在移動(dòng)設(shè)備上運(yùn)行 Android 2.3.4.它是 Nexus S 和運(yùn)行庫(kù)存的 Android.在模擬器中(運(yùn)行 Android 2.2)不會(huì)出現(xiàn)這個(gè)問(wèn)題.
I am running Android 2.3.4 on my mobile device. It is a Nexus S and running stock Android. In the emulator (running Android 2.2) this problem does not occur.
當(dāng)我旋轉(zhuǎn)手機(jī)時(shí),Android 會(huì)自動(dòng)替換旋轉(zhuǎn)前 EditText 中的文本.我沒(méi)有使用 savedInstanceState 做任何事情.Android 本身就是這樣做的.
When I rotate the phone, Android automatically replaces the text that was in the EditText before the rotation. I'm not using savedInstanceState to do anything. Android is doing this itself.
我的問(wèn)題:
假設(shè)test"一詞在 EditText 中.當(dāng)我旋轉(zhuǎn)手機(jī)時(shí),Android 會(huì)在重新創(chuàng)建 Activity 時(shí)將testtest"放入 EditText.這僅在我使用虛擬鍵盤(pán)鍵入 EditText 時(shí)發(fā)生,我沒(méi)有單擊虛擬鍵盤(pán)上的完成"按鈕,我按下返回以移除虛擬鍵盤(pán),然后旋轉(zhuǎn)設(shè)備.如果我使用完成"按鈕而不是返回按鈕,則不會(huì)出現(xiàn)問(wèn)題.
Suppose the word "test" is in the EditText. When I rotate the phone, Android will place "testtest" into the EditText when the Activity is re-created. This only happens when I use the virtual keyboard to type into the EditText, I do not click the "done" button on the virtual keyboard, I press back to remove the virtual keyboard, and I then rotate the device. If I use the "done" button instead of the back button, the problem does not occur.
有什么想法嗎?正如我所說(shuō),我不設(shè)置文本.所有調(diào)用 setText 的行都被注釋掉了.
Any ideas? As I said, I am NOT setting the text. All lines that call setText have been commented out.
更新 1:我已經(jīng)注釋掉了這個(gè) Activity 中的所有內(nèi)容,除了 onCreate() 方法.問(wèn)題仍然存在.
更新 2:我創(chuàng)建了一個(gè)新 Activity.這個(gè)全新的 Activity 只有一個(gè) onCreate() 方法.onCreate() 方法中唯一的事情是調(diào)用 setContentView(使用相同的布局文件)并調(diào)用 super 的 onCreate().問(wèn)題仍然存在.我難住了.我唯一能猜到的是布局文件有些古怪.我不知道那會(huì)是什么.
更新 3:除了 EditText 之外,我已經(jīng)從布局中刪除了所有內(nèi)容.問(wèn)題仍然存在.
推薦答案
我也遇到過(guò)類(lèi)似的問(wèn)題,但只有在 EditText 的 AutoComplete 開(kāi)啟時(shí)才能看到.
I had a similar problem but I only see it when the AutoComplete is turned on for the EditText.
我的解決方法是禁用自動(dòng)完成功能.
My work around was to disable autocomplete.
<EditText
.
.
.
android:inputType="textMultiLine|textNoSuggestions"
/>
這篇關(guān)于EditText 在旋轉(zhuǎn)時(shí)翻倍的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!