0

How can I add a vibrate event to the onLongClick() method?

Parker
  • 7,244
  • 12
  • 70
  • 92
smileVann
  • 554
  • 1
  • 6
  • 15
  • @Override public boolean onLongClick(View v) { switch (v.getId()) { some case here } TextView textview = (TextView)findViewById(v.getid()); .... } //i want to add a vibrate event to the textview .But i have a mistake,did you know how to do?thx! – smileVann Mar 01 '12 at 02:53

1 Answers1

3

In your onLongClick listener use this

Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);

Add this permission to your manifest file

<uses-permission android:name="android.permission.VIBRATE"/>
blessanm86
  • 31,439
  • 14
  • 68
  • 79
  • but i want the specified TextView to vibrate instead of the whole device to vibrate when i click it ,i think android device support it – smileVann Mar 01 '12 at 04:50
  • http://sherifandroid.blogspot.in/2011/09/vibratingtextview.html and http://stackoverflow.com/questions/7512124/vibrating-textview-configure-attributes-for-custom-views – blessanm86 Mar 01 '12 at 05:00