EditText does not show current input (Android 4)

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(""); // clear the input view ... } 

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()); 
+5
source share
3 answers

I had exactly the same problem, even at lower API levels. There is an error when using:

 editText.setText(""); 

many times to remove EditText. Here is a workaround that helped:

 TextKeyListener.clear(editText.getText()); 

You can read about this error on the Google Code website: http://code.google.com/p/android/issues/detail?id=17508

Hope this helps!

+3
source

try installing OnClickListener on your Finish button. Let onClick(View v) look like this:

 @Override public void onClick(View v){ kontextTV1.setText(editText1.getText.toString()); } 

If you pull out the text when the user clicks the Finish button, you don’t have to use the observer class. This should also work on all versions of Android. (Get / Set on edittext and textview are unlikely to change). It will handle

If you want to process the "done" button on the keyboard, try:

 editText1.setOnKeyListener(new OnKeyListener() { public boolean onKey(final View v, final int keyCode, final KeyEvent event) { if (KeyEvent.KEYCODE_ENTER == keyCode) { //... } } 
+1
source

Why not use afterTextChanged instead of editorActionListener?

0
source

All Articles