Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
808 views
in Technique[技术] by (71.8m points)

set - Keyboard suggestions cause part of Android EditText.setError() message to not display

When I'm using edittext.setError("enter a comment") in android, it works fine until the keyboard suggestions come up and the error gets pushed above the edittext, after which it does not display the whole error message.

Why is it doing this?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

So when the text is changed it should be gone. I don't know why this doesn't happen in your case.

It should also be cleared when error message is null, so one trick could be:

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);
        }
    }
}); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...