My Android app has an EditText where you can enter short messages (one line). Pressing the DONE key on the keyboard will add a message to the log view mode ( TextView ) and clear the input view.
Here is a snippet from my xml view:
<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 view, I use OnEditorActionListener .
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { ... String input = mInputView.getText().toString(); mInputView.setText("");
Problem
I had no problems on Android 1.6 - 3. But starting with IceCreamSandwich (> = Android 4) there is a strange error that occurs periodically (in most cases after ~ 10-30 inputs).
When you enter some text, the input type remains empty. The cursor is still flashing at position 0, the text is not displayed. Although clicking on DONE adds (invisible) text to the magazine view above, and the text can be read. In addition, hiding the keyboard makes the text as an EditText visible.
Decision
As indicated in the accepted answer, this is (not so much) a known Android OS error. A simple solution is to clear the EditText view differently:
TextKeyListener.clear(mInputView.getText());
ottel142
source share