How can I add a vibrate event to the onLongClick() method?
Asked
Active
Viewed 1,051 times
0
vallismortis
- 6,682
- 12
- 70
- 85
smileVann
- 544
- 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 Answers
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
- 30,847
- 14
- 65
- 77
-
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