Thursday, 14 February 2013

Validate or Check if EditText is empty?

Answer -1:
EditText usernameEditText = (EditText) findViewById(R.id.editUsername);

String Username = usernameEditText.getText().toString();
 

if (Username.matches("")) {
    Toast.makeText(this, "You did not enter a username", Toast.LENGTH_SHORT).show();
    return;
}



Answer -2:


private boolean isEmpty(EditText etText) {
    if (etText.getText().toString().trim().length() > 0) {
        return false;
    } else {
        return true;
    }
}

If function return false means edittext is not empty and return true means edittext is empty




No comments:

Post a Comment