Crazy Android Handouts-Learn notes (three)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.