Check if edittext is empty

Approach 1:


EditText txtUserName = (EditText) findViewById(R.id.txtUsername);
String strUserName = usernameEditText.getText().toString();
if (strUserName.trim().equals("")) {
    Toast.makeText(this, "plz enter your name ", Toast.LENGTH_SHORT).show();
    return;
}
 
 
 

Approach 2:

 
You can use length() from EditText.
public boolean isEditTextEmpty(EditText mInput){
   if(mInput.length() == 0)
      return true;
   else
      return false;
}

 

Comments

Popular posts from this blog

How to draw an overlay on a SurfaceView used by Camera on Android?

Android TCP Connection Chat application

Create EditText with dropdown in android