Winona Winona - 4 months ago 27
Android Question

Check if EditText is empty.

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

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