The first type: Anonymous inner class as event listener class
The second type: inner class as listener
The third type: Activity itself as an event listener
Fourth type: External class as Listener
The Mybuttonlistener listener is triggered by the program when the user clicks the button
External Mybuttonlistener class
It is uncommon to define event listener classes using top-level classes, mainly because of the following two reasons:
1, event listener is usually a specific GUI interface, defined as external class does not improve the cohesion of the program.
2. The external class event listener does not have free access to the components in the class that created the GUI interface, and the programming is not concise.
However, if an event listener does need to be shared by multiple GUI interfaces and is primarily an implementation of some kind of business logic, consider defining an event listener class in the form of an external class.
Fifth: Bind directly to the label
Android also has a simpler way of binding event listeners to bind event handlers directly in the interface layout file for the specified tag.
For many Android tags, they support attributes such as onclick, Onlongclick, and the property value of a property that is a shape such as xxx
(View Source)
Method name of the method. To add a property to a button in a layout file, such as code:
Bind an event-handling method to the button buttons: Clickhanlder, which means that the developer needs to define a void Clickhanler (View source) method in the corresponding activity in the interface layout. This method will be responsible for handling the Click event on the button.
Here is the Java code for the interface layout:
Reference: http://www.apkbus.com/android-18459-1-1.html