How to Validate Edittext in Android With Example

How to Validate Edittext in Android With Example

In this tutorial i am going to explain about How to Validate Edittext in Android With Example. In my previous tutorial i have explained about

Implementation of How to Validate Edittext in Android:

Validation is the common practice in any form before submitting it into server. So in this tutorial we will see how to Validate Edittext in Android with example.




For demo purpose i have created a new project and AndroidSetErrorExample. I have named my default activity as SetErrorActivity.java. Now open the layout xml file and update the below code. It contains to edittext and a button field.

Now open the SetErrorActivity.java file and update the below code. Here i am creating reference to xml widgets and then creating button onclicklistener to validate the edittext. Inside the onclick listener i am checking whether the edittext value is empty. If so i am setting error message using seterror method. You can read about seterror here.

Open the string resource file and update the below resources.

Our final manifest file will look like below.

Output:

Now if you run the program you can see the output of How to Validate Edittext in Android With Example.

Source Code:

You can download the Source code of How to Validate Edittext in Android With Example from the below link.

Source code of How to Validate Edittext in Android With Example

Conclusion:

Hope you learned How to Validate Edittext in Android. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!