How To Check Edit Text Is Empty
I am developing a application in which if i click a button it woul d check that all the edit text are empty or something written and providing similar alert box for that message.I
Solution 1:
you can try this :
if ((f.trim().equals('') || (f1.trim().equals('') ||........) {
// Error , one or more editText are empty
}
else
{
// all editText are not empty
}
Solution 2:
// Edit
I think you have it the wrong way, where your if statment is when every is filled in, your else when one of the fields is empty
---- previous answer ----
You can do it like this.
if(editText.getText().toString().length() > 0) {
// editText is not empty
}
if(editText.getText().toString().length() == 0) {
// editText is empty
}
Solution 3:
Mats and Houcine answers are valid but you can even do shorter using isEmpty()
:
if(editText.getText().toString().isEmpty()) {
// editText is empty
} else {
// editText is not empty
}
Post a Comment for "How To Check Edit Text Is Empty"