0

There is a question for "How to enable vibration on an ImageView, this question is how to do the same thing with a toggle button.

Current implementation (haptic feedback only on certain devices):

        toggleBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (zero) {
                setOne();
                myVib.vibrate(5);
            } else {
                setZero();
                myVib.vibrate(5);
            }
        }
    });

1 Answers1

0

JUST COPIED IT FROM THIS SO ANSWER

the code is doing it for a view so i guess you can also use it for button

A example to Mayra is, for run the Haptic Feedback is by use this code.

View view = findViewById(...)
view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);

And this line of code can easy be include in you onclick action. The good part with this is you do not need to set a permission in the AndroidManifest ( I do not need this on SdkVersion "7" (2.1 or 2.3 is 7 ) )

Also do notes in my code here this will be run only if the use as enable Haptic Feedback as global. See http://developer.android.com/reference/android/view/HapticFeedbackConstants.html for alway use it.

Community
  • 1
  • 1
Neo
  • 1,359
  • 14
  • 34