Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
821 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...