October 2018
Intermediate to advanced
464 pages
15h 17m
English
In most examples used in this book, we set up the onClick listener in XML using the following attribute:
android:onClick=""
You may notice the XML onClick() method callback requires the same method signature as the setOnClickListener .onClick() callback:
public void onClick(View v) {}
That's because Android automatically sets up the callback for us when we use the XML onClick attribute. This example also demonstrates that we can have multiple listeners on a single View.
The last point to note is that the onLongClick() method returns a Boolean, as do most of the other event listeners. true is returned to indicate the event has been handled.