My Android application contains an EditText view where you can type some short messages (single line). Pressing the keyboard's DONE key will append the message to a log view above (TextView) and clear the input view.
Here's a snippet from my view xml:
<LinearLayout ...>
<TextView
android:id="@+id/logView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/inputView"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:imeOptions="actionDone"
android:singleLine="true" />
</LinearLayout>
To handle the input and reset the view, I use the OnEditorActionListener.
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
...
String input = mInputView.getText().toString();
mInputView.setText(""); // clear the input view
...
}
I did not experience any problems on Android 1.6 - 3. But starting with IceCreamSandwich (>= Android 4) there's a weird bug which occurs intermittently (in most cases after ~10-30 inputs).
When you type some text, the input view remains blank. The cursor still blinks on position 0, no text is shown. Though a click on DONE adds the (invisible) text to the log view above and the text can be read. Also hiding the keyboard makes the text in the EditText view visible.
As stated in the accepted answer this is a (not so much) known bug of the Android OS. The simple solution is to clear the EditText view in a different way:
TextKeyListener.clear(mInputView.getText());
I had exactly the same issue, even on lower API levels. There's a bug when using:
editText.setText("");
many times to empty an EditText. Here's a workaround that helped:
TextKeyListener.clear(editText.getText());
You can read about this bug on the Google Code site: http://code.google.com/p/android/issues/detail?id=17508
Hope it helps!