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
320 views
in Technique[技术] by (71.8m points)

android - EditText setError() with no message just the icon

Currently I have a really simple code that validates EditText fields and when the user hits the button at the end it checks them. It will put errors in all the fields with this:

if (!emailmatcher.matches()) {
    email.setError("Invalid Email");  
}
if (!zipmatcher.matches()) {
    zipcode.setError("Invalid ZipCode");                     
}

My problem that is the keyboard will popup and will move the error bubble to a random place. I was hoping to not have a error bubbles with a message but keep the error icons in invalid EditText fields. I tried inputting setError(null) but that doesn't work. Any Ideas?

question from:https://stackoverflow.com/questions/6538709/edittext-seterror-with-no-message-just-the-icon

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

1 Answer

0 votes
by (71.8m points)

Your code perfect to show icon only.

As EditText is show anything related to when it has focused. So just change your code to like that...

if (!emailmatcher.matches()) {
    email.requestFocus();
    email.setError("Invalid Email");  
}
if (!zipmatcher.matches()) {
    zipcode.requestFocus();
    zipcode.setError("Invalid ZipCode");                     
}

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

...