android - 键盘建议导致部分 Android EditText.setError() 消息不显示

标签 android set android-edittext

当我在 android 中使用 edittext.setError("enter a comment") 时,它工作正常,直到出现键盘建议并且错误被推送到 edittext,之后它不会显示整个错误消息。

为什么要这样做?

After entering into the textbox, the balloon pop-up now appears above the textbox

最佳答案

setError
Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. If the error is null, the error message and icon will be cleared.

所以当文本被更改时,它应该消失了。我不知道为什么这不会发生在你的情况下。

当错误消息为空时,它也应该被清除,所以一个技巧可能是:

edittext = (EditText)findViewById(R.id.foo); // add below this line
edittext.addTextChangedListener(new TextWatcher() {
    public void afterTextChanged(Editable s) {}
    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    public void onTextChanged(CharSequence s, int start, int before, int count){
        if(s != null && s.length() > 0 && edittext.getErrorMessage() != null) {
            edittext.setErrorMessage(null);
        }
    }
}); 

关于android - 键盘建议导致部分 Android EditText.setError() 消息不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7747268/

相关文章:

python - Python 中的笛卡尔积通用函数

c++ - IEEE float std::map 和 std::set 的有效键类型吗?

Android:单行中的EditText提示

java - 软输入键盘没有隐藏在 edittext 上

android - 如何创建 json 的字符串表示

android - 用于管理 Play 商店订阅的链接

android - 什么 gradle 任务从远程存储库中提取依赖项?

android - 更新后保留 SQLite 数据

c++ - 在 C++ 中设置差异

android - 如何防止键盘隐藏我的 EditText?