To verify that EditText is empty

Asked 1 years ago, Updated 1 years ago, 108 views

I have 5 EditTexts on my app. What I'm curious about is whether Android provides a method to know if the content of EditText is empty. Or do I have to code it separately?

android-edittext android

2022-09-22 22:14

1 Answers

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

Yes, I think you can do it like this.


2022-09-22 22:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.