Tuesday 26 August 2014

Set error message in edittext android


Set error message in edittext android

This is the very useful when you want to show the error messages for the edittext field when the user enter wrong information.this is very simply 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:



DOWNLOAD FULL SOURCE CODE

No comments: