EditText上不显示电流输入端(安卓4.0) [英] EditText does not show current input (Android 4)

查看:120
本文介绍了EditText上不显示电流输入端(安卓4.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid应用程序包含一个的EditText 视图,您可以键入一些短消息(单线)。 pressing键盘的完成的键将追加消息日志视图上面(的 TextView的),并清除输入视图。

下面是从我的观点的XML代码段:

 < LinearLayout中...>
    <的TextView
        机器人:ID =@ + ID /日志查看
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT/>

    <的EditText
        机器人:ID =@ + ID / inputView
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =FILL_PARENT
        机器人:imeOptions =actionDone
        机器人:单线=真/>
< / LinearLayout中>
 

要处理输入和复位的观点,我用的是 OnEditorActionListener

  @覆盖
公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
    ...
    字符串输入= mInputView.getText()的toString()。
    mInputView.setText(); //清除输入视图
    ...
}
 

问题

我没有遇到任何问题,在Android 1.6 - 。3,但用IceCreamSandwich(> =安卓4.0),有一个奇怪的错误,这错误间歇性地出现(在大多数情况下后〜10-30输入)

当你输入一些文字,输入视图保持空白。光标仍然闪烁的位置为0,表示没有文字。虽然上的完成点击的添加(不可见)的文本上面的日志查看和文本可以被读出。另外隐藏的键盘使得在的EditText文本视图可见。

解决方案

作为公认的答案说,这是Android操作系统的(没有这么多),已知的bug。最简单的解决方法是清除不同的方式的EditText观点:

  TextKeyListener.clear(mInputView.getText());
 

解决方案

我有完全一样的问题,即使在较低的空气污染水平。还有,当使用一个错误:

  editText.setText();
 

多次清空一个EditText。这里有一个解决方法,帮助:

  TextKeyListener.clear(editText.getText());
 

您可以了解在谷歌code部位此错误:的 HTTP://$c$c.google.com/p/android/issues/detail ID = 17508

希望它能帮助!

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
    ...
}

The problem

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.

Solution

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!

这篇关于EditText上不显示电流输入端(安卓4.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆