how to set vibrate animation and device vibration to edittext?










1















What i want : I want to create a edit text that will vibrate if given input is empty or invalid.



Example : In login screen the password edit text is empty or invalid, than edit text will vibrate at the same time my android device need to vibrate for some time how to create that it?

thanks in advance










share|improve this question
























  • what have you tried so far?

    – V-rund Puro-hit
    Nov 13 '18 at 7:03











  • what is a problem for you: to check if edittext is empty, or to vibrate

    – Vladyslav Matviienko
    Nov 13 '18 at 7:03











  • i tried to set the edittext vibrate and got it. now need to set the android device vibration

    – Agilanbu
    Nov 13 '18 at 7:05











  • if my edittext is empty i need to set android device vibrate and edittext vibrate @VladyslavMatviienko

    – Agilanbu
    Nov 13 '18 at 7:08











  • try searching on google before asking question stackoverflow.com/a/13950364/5148289

    – V-rund Puro-hit
    Nov 13 '18 at 7:10















1















What i want : I want to create a edit text that will vibrate if given input is empty or invalid.



Example : In login screen the password edit text is empty or invalid, than edit text will vibrate at the same time my android device need to vibrate for some time how to create that it?

thanks in advance










share|improve this question
























  • what have you tried so far?

    – V-rund Puro-hit
    Nov 13 '18 at 7:03











  • what is a problem for you: to check if edittext is empty, or to vibrate

    – Vladyslav Matviienko
    Nov 13 '18 at 7:03











  • i tried to set the edittext vibrate and got it. now need to set the android device vibration

    – Agilanbu
    Nov 13 '18 at 7:05











  • if my edittext is empty i need to set android device vibrate and edittext vibrate @VladyslavMatviienko

    – Agilanbu
    Nov 13 '18 at 7:08











  • try searching on google before asking question stackoverflow.com/a/13950364/5148289

    – V-rund Puro-hit
    Nov 13 '18 at 7:10













1












1








1








What i want : I want to create a edit text that will vibrate if given input is empty or invalid.



Example : In login screen the password edit text is empty or invalid, than edit text will vibrate at the same time my android device need to vibrate for some time how to create that it?

thanks in advance










share|improve this question
















What i want : I want to create a edit text that will vibrate if given input is empty or invalid.



Example : In login screen the password edit text is empty or invalid, than edit text will vibrate at the same time my android device need to vibrate for some time how to create that it?

thanks in advance







android animation android-edittext vibrate






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 11:01









Fantômas

32.6k156388




32.6k156388










asked Nov 13 '18 at 6:59









AgilanbuAgilanbu

1,3451419




1,3451419












  • what have you tried so far?

    – V-rund Puro-hit
    Nov 13 '18 at 7:03











  • what is a problem for you: to check if edittext is empty, or to vibrate

    – Vladyslav Matviienko
    Nov 13 '18 at 7:03











  • i tried to set the edittext vibrate and got it. now need to set the android device vibration

    – Agilanbu
    Nov 13 '18 at 7:05











  • if my edittext is empty i need to set android device vibrate and edittext vibrate @VladyslavMatviienko

    – Agilanbu
    Nov 13 '18 at 7:08











  • try searching on google before asking question stackoverflow.com/a/13950364/5148289

    – V-rund Puro-hit
    Nov 13 '18 at 7:10

















  • what have you tried so far?

    – V-rund Puro-hit
    Nov 13 '18 at 7:03











  • what is a problem for you: to check if edittext is empty, or to vibrate

    – Vladyslav Matviienko
    Nov 13 '18 at 7:03











  • i tried to set the edittext vibrate and got it. now need to set the android device vibration

    – Agilanbu
    Nov 13 '18 at 7:05











  • if my edittext is empty i need to set android device vibrate and edittext vibrate @VladyslavMatviienko

    – Agilanbu
    Nov 13 '18 at 7:08











  • try searching on google before asking question stackoverflow.com/a/13950364/5148289

    – V-rund Puro-hit
    Nov 13 '18 at 7:10
















what have you tried so far?

– V-rund Puro-hit
Nov 13 '18 at 7:03





what have you tried so far?

– V-rund Puro-hit
Nov 13 '18 at 7:03













what is a problem for you: to check if edittext is empty, or to vibrate

– Vladyslav Matviienko
Nov 13 '18 at 7:03





what is a problem for you: to check if edittext is empty, or to vibrate

– Vladyslav Matviienko
Nov 13 '18 at 7:03













i tried to set the edittext vibrate and got it. now need to set the android device vibration

– Agilanbu
Nov 13 '18 at 7:05





i tried to set the edittext vibrate and got it. now need to set the android device vibration

– Agilanbu
Nov 13 '18 at 7:05













if my edittext is empty i need to set android device vibrate and edittext vibrate @VladyslavMatviienko

– Agilanbu
Nov 13 '18 at 7:08





if my edittext is empty i need to set android device vibrate and edittext vibrate @VladyslavMatviienko

– Agilanbu
Nov 13 '18 at 7:08













try searching on google before asking question stackoverflow.com/a/13950364/5148289

– V-rund Puro-hit
Nov 13 '18 at 7:10





try searching on google before asking question stackoverflow.com/a/13950364/5148289

– V-rund Puro-hit
Nov 13 '18 at 7:10












2 Answers
2






active

oldest

votes


















0














Alright here is what you need..



Vibrate Animation



put these two xml files inside res/anim folder



vibrate.xml



<?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_5" />


cycle_5.xml



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


Vibrating Phone



use these method to vibrate your phone for 500 milliseconds



public void shakeItBaby() 
int DURATION = 500; // you can change this according to your need
if (Build.VERSION.SDK_INT >= 26)
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
else
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(DURATION);




and don't forget to put permission in menifest



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


Putting all together



now use them both wile validating your EditText



Animation vibrate = AnimationUtils.loadAnimation(this, R.anim.vibrate);

if (paytm_amt.getText().toString().trim().isEmpty())
paytm_num.setError("Please Enter PayTM Number");
paytm_num.startAnimation(vibrate);
shakeItBaby();
else
// do something



Happy Coding..






share|improve this answer






























    0














    Components



     EditText mPassword = findViewById(R.id.edtPassword);
    Button mLogin = findViewById(R.id.btnLogin);


    Android Device Vibration



     private void AndroidDeviceVibrate() // Android Device Vibration
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds only
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
    v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
    else
    v.vibrate(500); // deprecated in API 26




    Edit text vibrate Animation



     public TranslateAnimation VibrateError() // Edit text vibrate Animation
    TranslateAnimation vibrate = new TranslateAnimation(0, 10, 0, 0);
    vibrate.setDuration(600);
    vibrate.setInterpolator(new CycleInterpolator(8));
    return vibrate;



    Finally,



    mLogin.setOnClickListener(new View.OnClickListener() 
    @Override
    public void onClick(View view)
    String strPass = mPassword.getText().toString();
    if (TextUtils.isEmpty(strPass))
    AndroidDeviceVibrate(); // Android Device Vibrate
    mPassword.startAnimation(VibrateError()); // Edit text vibrate Animation


    );





    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275469%2fhow-to-set-vibrate-animation-and-device-vibration-to-edittext%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Alright here is what you need..



      Vibrate Animation



      put these two xml files inside res/anim folder



      vibrate.xml



      <?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_5" />


      cycle_5.xml



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


      Vibrating Phone



      use these method to vibrate your phone for 500 milliseconds



      public void shakeItBaby() 
      int DURATION = 500; // you can change this according to your need
      if (Build.VERSION.SDK_INT >= 26)
      ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
      else
      ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(DURATION);




      and don't forget to put permission in menifest



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


      Putting all together



      now use them both wile validating your EditText



      Animation vibrate = AnimationUtils.loadAnimation(this, R.anim.vibrate);

      if (paytm_amt.getText().toString().trim().isEmpty())
      paytm_num.setError("Please Enter PayTM Number");
      paytm_num.startAnimation(vibrate);
      shakeItBaby();
      else
      // do something



      Happy Coding..






      share|improve this answer



























        0














        Alright here is what you need..



        Vibrate Animation



        put these two xml files inside res/anim folder



        vibrate.xml



        <?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_5" />


        cycle_5.xml



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


        Vibrating Phone



        use these method to vibrate your phone for 500 milliseconds



        public void shakeItBaby() 
        int DURATION = 500; // you can change this according to your need
        if (Build.VERSION.SDK_INT >= 26)
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
        else
        ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(DURATION);




        and don't forget to put permission in menifest



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


        Putting all together



        now use them both wile validating your EditText



        Animation vibrate = AnimationUtils.loadAnimation(this, R.anim.vibrate);

        if (paytm_amt.getText().toString().trim().isEmpty())
        paytm_num.setError("Please Enter PayTM Number");
        paytm_num.startAnimation(vibrate);
        shakeItBaby();
        else
        // do something



        Happy Coding..






        share|improve this answer

























          0












          0








          0







          Alright here is what you need..



          Vibrate Animation



          put these two xml files inside res/anim folder



          vibrate.xml



          <?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_5" />


          cycle_5.xml



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


          Vibrating Phone



          use these method to vibrate your phone for 500 milliseconds



          public void shakeItBaby() 
          int DURATION = 500; // you can change this according to your need
          if (Build.VERSION.SDK_INT >= 26)
          ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
          else
          ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(DURATION);




          and don't forget to put permission in menifest



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


          Putting all together



          now use them both wile validating your EditText



          Animation vibrate = AnimationUtils.loadAnimation(this, R.anim.vibrate);

          if (paytm_amt.getText().toString().trim().isEmpty())
          paytm_num.setError("Please Enter PayTM Number");
          paytm_num.startAnimation(vibrate);
          shakeItBaby();
          else
          // do something



          Happy Coding..






          share|improve this answer













          Alright here is what you need..



          Vibrate Animation



          put these two xml files inside res/anim folder



          vibrate.xml



          <?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_5" />


          cycle_5.xml



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


          Vibrating Phone



          use these method to vibrate your phone for 500 milliseconds



          public void shakeItBaby() 
          int DURATION = 500; // you can change this according to your need
          if (Build.VERSION.SDK_INT >= 26)
          ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
          else
          ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(DURATION);




          and don't forget to put permission in menifest



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


          Putting all together



          now use them both wile validating your EditText



          Animation vibrate = AnimationUtils.loadAnimation(this, R.anim.vibrate);

          if (paytm_amt.getText().toString().trim().isEmpty())
          paytm_num.setError("Please Enter PayTM Number");
          paytm_num.startAnimation(vibrate);
          shakeItBaby();
          else
          // do something



          Happy Coding..







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 8:36









          V-rund Puro-hitV-rund Puro-hit

          3,99082045




          3,99082045























              0














              Components



               EditText mPassword = findViewById(R.id.edtPassword);
              Button mLogin = findViewById(R.id.btnLogin);


              Android Device Vibration



               private void AndroidDeviceVibrate() // Android Device Vibration
              Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds only
              if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
              v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
              else
              v.vibrate(500); // deprecated in API 26




              Edit text vibrate Animation



               public TranslateAnimation VibrateError() // Edit text vibrate Animation
              TranslateAnimation vibrate = new TranslateAnimation(0, 10, 0, 0);
              vibrate.setDuration(600);
              vibrate.setInterpolator(new CycleInterpolator(8));
              return vibrate;



              Finally,



              mLogin.setOnClickListener(new View.OnClickListener() 
              @Override
              public void onClick(View view)
              String strPass = mPassword.getText().toString();
              if (TextUtils.isEmpty(strPass))
              AndroidDeviceVibrate(); // Android Device Vibrate
              mPassword.startAnimation(VibrateError()); // Edit text vibrate Animation


              );





              share|improve this answer



























                0














                Components



                 EditText mPassword = findViewById(R.id.edtPassword);
                Button mLogin = findViewById(R.id.btnLogin);


                Android Device Vibration



                 private void AndroidDeviceVibrate() // Android Device Vibration
                Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds only
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
                v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
                else
                v.vibrate(500); // deprecated in API 26




                Edit text vibrate Animation



                 public TranslateAnimation VibrateError() // Edit text vibrate Animation
                TranslateAnimation vibrate = new TranslateAnimation(0, 10, 0, 0);
                vibrate.setDuration(600);
                vibrate.setInterpolator(new CycleInterpolator(8));
                return vibrate;



                Finally,



                mLogin.setOnClickListener(new View.OnClickListener() 
                @Override
                public void onClick(View view)
                String strPass = mPassword.getText().toString();
                if (TextUtils.isEmpty(strPass))
                AndroidDeviceVibrate(); // Android Device Vibrate
                mPassword.startAnimation(VibrateError()); // Edit text vibrate Animation


                );





                share|improve this answer

























                  0












                  0








                  0







                  Components



                   EditText mPassword = findViewById(R.id.edtPassword);
                  Button mLogin = findViewById(R.id.btnLogin);


                  Android Device Vibration



                   private void AndroidDeviceVibrate() // Android Device Vibration
                  Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds only
                  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
                  v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
                  else
                  v.vibrate(500); // deprecated in API 26




                  Edit text vibrate Animation



                   public TranslateAnimation VibrateError() // Edit text vibrate Animation
                  TranslateAnimation vibrate = new TranslateAnimation(0, 10, 0, 0);
                  vibrate.setDuration(600);
                  vibrate.setInterpolator(new CycleInterpolator(8));
                  return vibrate;



                  Finally,



                  mLogin.setOnClickListener(new View.OnClickListener() 
                  @Override
                  public void onClick(View view)
                  String strPass = mPassword.getText().toString();
                  if (TextUtils.isEmpty(strPass))
                  AndroidDeviceVibrate(); // Android Device Vibrate
                  mPassword.startAnimation(VibrateError()); // Edit text vibrate Animation


                  );





                  share|improve this answer













                  Components



                   EditText mPassword = findViewById(R.id.edtPassword);
                  Button mLogin = findViewById(R.id.btnLogin);


                  Android Device Vibration



                   private void AndroidDeviceVibrate() // Android Device Vibration
                  Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds only
                  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
                  v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
                  else
                  v.vibrate(500); // deprecated in API 26




                  Edit text vibrate Animation



                   public TranslateAnimation VibrateError() // Edit text vibrate Animation
                  TranslateAnimation vibrate = new TranslateAnimation(0, 10, 0, 0);
                  vibrate.setDuration(600);
                  vibrate.setInterpolator(new CycleInterpolator(8));
                  return vibrate;



                  Finally,



                  mLogin.setOnClickListener(new View.OnClickListener() 
                  @Override
                  public void onClick(View view)
                  String strPass = mPassword.getText().toString();
                  if (TextUtils.isEmpty(strPass))
                  AndroidDeviceVibrate(); // Android Device Vibrate
                  mPassword.startAnimation(VibrateError()); // Edit text vibrate Animation


                  );






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 10:39









                  AgilanbuAgilanbu

                  1,3451419




                  1,3451419



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275469%2fhow-to-set-vibrate-animation-and-device-vibration-to-edittext%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Darth Vader #20

                      How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                      Ondo