問題描述
我遇到了 EditText 控件的問題.這個問題只發生在這個特定的活動上,沒有其他帶有 EditTexts 的活動.我已刪除此 EditText 的所有 setText 調用,但問題仍然存在.
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.
我在移動設備上運行 Android 2.3.4.它是 Nexus S 和運行庫存的 Android.在模擬器中(運行 Android 2.2)不會出現這個問題.
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.
當我旋轉手機時,Android 會自動替換旋轉前 EditText 中的文本.我沒有使用 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.
我的問題:
假設test"一詞在 EditText 中.當我旋轉手機時,Android 會在重新創建 Activity 時將testtest"放入 EditText.這僅在我使用虛擬鍵盤鍵入 EditText 時發生,我沒有單擊虛擬鍵盤上的完成"按鈕,我按下返回以移除虛擬鍵盤,然后旋轉設備.如果我使用完成"按鈕而不是返回按鈕,則不會出現問題.
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.
有什么想法嗎?正如我所說,我不設置文本.所有調用 setText 的行都被注釋掉了.
Any ideas? As I said, I am NOT setting the text. All lines that call setText have been commented out.
更新 1:我已經注釋掉了這個 Activity 中的所有內容,除了 onCreate() 方法.問題仍然存在.
更新 2:我創建了一個新 Activity.這個全新的 Activity 只有一個 onCreate() 方法.onCreate() 方法中唯一的事情是調用 setContentView(使用相同的布局文件)并調用 super 的 onCreate().問題仍然存在.我難住了.我唯一能猜到的是布局文件有些古怪.我不知道那會是什么.
更新 3:除了 EditText 之外,我已經從布局中刪除了所有內容.問題仍然存在.
推薦答案
我也遇到過類似的問題,但只有在 EditText 的 AutoComplete 開啟時才能看到.
I had a similar problem but I only see it when the AutoComplete is turned on for the EditText.
我的解決方法是禁用自動完成功能.
My work around was to disable autocomplete.
<EditText
.
.
.
android:inputType="textMultiLine|textNoSuggestions"
/>
這篇關于EditText 在旋轉時翻倍的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!