vibration of Edittext in android

Create anim folder in resources and then create file named shake.xml and paste the below code

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="10" android:duration="1000"
    android:interpolator="@anim/cycle_7" />

and another file cycle_7.xml

<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />

and then in your java file

if(invalid)//check your input
{
   Animation shake = AnimationUtils.loadAnimation(Login.this, R.anim.shake);
   editText.startAnimation(shake);
}

For vibrate use the following code.

Vibrator vibe = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

Then, in the OnTextChanged Listener method use the following code.

vibe.vibrate(50); // 50 is time in ms

And don't forget you need to add the permission to the manifest (after the </application> tag):

<uses-permission android:name="android.permission.VIBRATE" />

If anyone is looking for a method to do what @Priya suggested programatically, then you can try this.

public TranslateAnimation shakeError() {
        TranslateAnimation shake = new TranslateAnimation(0, 10, 0, 0);
        shake.setDuration(500);
        shake.setInterpolator(new CycleInterpolator(7));
        return shake;
}

And then:

myEditText.startAnimation(shakeError());