Event handling for Android
3.1 Android provides two sets of event handling mechanisms: listener-based event handling, callback-based event handling.
3.2 Monitoring-based event handling
The processing model of 3.2.1 Monitoring mainly involves three kinds of objects: EventSource, Event, EventListener.
The event handling mechanism of Android is a delegate-type (delegation) Event handling method: The general component delegates the entire event processing to a specific object (event listener), and can delegate all possible events to different event listeners for processing. You can also allow a class of events to be handled using the same event listener.
The event listener class is a special class that must implement a listener interface.
3.2.2 Events and event listeners if the event is simple enough and the information encapsulated in the event is limited, there is no need to encapsulate the event object and access the event listener. But for keyboard events, touch screen events, the program needs to get the details of the event, and Android encapsulates the event information into a Xxxevent object and passes it to the event listener.
( source \03\3.2\plane) Add Touch events:
Planeview.setontouchlistener (New View.ontouchlistener (){
@Override Public Boolean OnTouch (View V, motionevent event)
......
Description : The event listener class used by Planeview is an inner class that uses an inner class to reuse the listener class in the current class, since the listener class is an inner class of an external class, so you have free access to all interface components of the external class. This is also the two advantages of the inner class.
3.2.4 external classes are uncommon as event listener classes because they are not conducive to increasing the cohesion of the program and are not free to access the components in the class that created the GUI interface. However, if a listener does need to be shared by multiple GUI interfaces, and the implementation of some kind of business logic is primarily done, consider defining an event listener class in the form of an external class.
( source \03\3.2\sendsms)