In activity, the activity must implement the Ontouchlistener and Ongesturelistener two interfaces, and override the methods in order to listen for touch-screen touch events and gesture time. I summarize according to the source code of Android 5.0 under Ontouchlistener
First, the Android event-handling mechanism is based on the Listener (listener), which is more than what we call today's touchscreen-related events, through Ontouchlistener. Second, all view subclasses can add listeners to a class of events by means of Setontouchlistener (), Setonkeylistener (), and so on. Thirdly, listener is generally provided in the form of Interface (interface), which contains one or more abstract (abstract) methods, and we need to implement these methods to accomplish Ontouch (), OnKey (), and so on. Thus, when we set the event listener for a view and implement the abstract method in it, the program can give the appropriate response through the CALLBAKC function when a particular event is dispatch to the view.
Paste the View structure: The source code shows that the Class View provides a total of 12 internal interfaces, including:Onkeylistener,ontouchlistener, Onhoverlistener, Ongenericmotionlistener, Onlongclicklistener, Ondraglistener, Onfocuschangelistener,OnClickListener, Oncreatecontextmenulistener, Onsystemuivisibilitychangelistener, Onattachstatechangelistener, Onapplywindowinsetslistener,
Paste the source code:
1 /**2 * Interface definition for a callback to being invoked when a touch event is3 * Dispatched to this view. The callback'll be invoked before the touch4 * Event is given to the view.5 */6 Public InterfaceOntouchlistener {7 /**8 * Called when a touch event was dispatched to a view. This allows listeners to9 * Get a chance to respond before the target view.Ten * One * @paramv The View the touch event has a been dispatched to. A * @paramEvent The Motionevent object containing full information about - * the event. - * @returnTrue If the listener has consumed the event, false otherwise. the */ - BooleanOnTouch (View V, motionevent event); -}
Android L (5.0) Source code gesture Recognition Ontouchlistener