Check if EditText is empty.

Winona picture Winona · Jun 9, 2011 · Viewed 473.8k times · Source

I have 5 EditTexts in android for users to input. I would like to know if I could have a method for checking all the 5 EditTexts if they are null. Is there any way to do this??

Answer

cvaldemar picture cvaldemar · Jun 9, 2011

I did something like this once;

EditText usernameEditText = (EditText) findViewById(R.id.editUsername);
sUsername = usernameEditText.getText().toString();
if (sUsername.matches("")) {
    Toast.makeText(this, "You did not enter a username", Toast.LENGTH_SHORT).show();
    return;
}