What does an EditText.getText() in android return if it is empty?

If it's empty, this will work:

if(mEditText.getText().toString().equals("")) {
    // stuff to run when it's empty
}

Even if it's empty, getText() will still return an Editable, so if you were trying to do this:

if(mEditText.getText().equals("")) {
    // stuff
}

It most certainly wasn't working.


No other possibility.

getText, infact, will never return null. It returns CharSequence whose contents may be empty.

Instead of doing getText().toString().equals("") or vice-versa, it may be faster to do getText().length() == 0

Tags:

Android