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!
View. OnClickListener is an interface, which defines the onClick(View) method. If you have a class which intends to listen for clicks, you should both implement the interface (if not already extending a class that does), and implement this method too. You have to use both; they're not somehow alternatives.
Using an OnClickListener You can also declare the click event handler programmatically rather than in an XML layout. This event handler code is mostly preferred because it can be used in both Activities and Fragments. There are two ways to do this event handler programmatically : Implementing View.
A Long Press refers to pressing a physical button or tap a virtual button on a touchscreen and holding it down for a second or two. Employed on touchscreens, smartphones, tablets, and smartwatches, the long press or long tap increases the user interface's flexibility.
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
Check out OnLongClickListener: http://developer.android.com/reference/android/view/View.OnLongClickListener.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With