Set error message in edittext android

Set error message in edittext android

This is very useful when you want to show the error messages for the Edittext field when the user enters wrong information.this is a very simple program only you have to use serError() method in the Edittext.

Step 1

Create button and implement onClickListener.

btnLogin.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});

Step 2

Validate the input fields and set the error in the input field.

if(edName.length()>3){
    if(edNumber.length()>3){
        Toast.makeText(getApplicationContext(), "Login success", Toast.LENGTH_SHORT).show();
    }else{
        edNumber.setError("Number Mininum length is 4");
    }
}else{
    edName.setError("Name Mininum length is 4");
}

Screenshot

velmm download code

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top