Notation 1: Inner class
Define an inner class to implement the Onclicklistener interface, and then register an instance of the inner class with the button.
Notation 2: Anonymous inner class
notation 3: Let the activity implement Onclicklistener interface, through this to register button click event, the replication OnClick method, by judging the view, centralized processing each button click event. This method is the most commonly used method for having multiple click events.
notation 4: Set the method to the OnClick property in the layout file, write the method name directly, and define the OnClick method in the activity.
method must be public void method name (View v)
notation 5: in the Xutils package, there is @onclick (r.id.xx) annotation, in the OnCreate method with Viewutils.inject (this) to make
The annotations take effect. The annotations must be written after Setcontentview.
This article is from the "line of the World" blog, please be sure to keep this source http://4259297.blog.51cto.com/4249297/1685738
4 ways to read and click events in Android