Reputation: 91
I am currently working on my final project for an intro android app development class. My final project was going to be a music player where you could click a button and it would play a certain note on a certain instrument. One thing I could not figure out is a way to have a sound file repeatedly play as a user holds a button. I understand how the OnClickListener works, but is there one for holding a button that I am missing? Thanks so much!
Upvotes: 9
Views: 41267
Reputation: 75629
You need to use touch listeners, not click listeners, because the latter, as name indicates is for click and click is is one time limited event, while touch is not.
See onTouch()
and in general docs: http://developer.android.com/guide/topics/ui/ui-events.html
Upvotes: 8
Reputation: 89
Check out OnLongClickListener: http://developer.android.com/reference/android/view/View.OnLongClickListener.html
Upvotes: 7
Reputation: 86948
Use an OnTouchListener or an SimpleOnGestureListener instead. Both of these listeners distinguish between when a user presses down on the screen and lifts up their finger.
Upvotes: 2