button click event, plainly on a method, Setonclicklistener (Onclicklistener).
As long as the passed parameter is a subclass of the Onclicklistener interface, it is easy to think of 2 implementations that are anonymous inner classes and define a class to implement this interface . There are also 2 ways to achieve this, and it is important to focus on:
1. Let the activity itself implement the Onclicklistener interface , passing the Setonclicklistener parameter with this.
Then, in the onclick (View V) method, the event source ID is judged.
Switch (V.getid ())
{
Case r.id.xxx000
Response code
Break
Case r.id.xxx111
Response code
Break
}
This is the way to define a class to implement an interface, just so that we don't define a class more. Directly let activity itself implement Onclicklistener interface, implement the OnClick method inside it.
This is defined in cases where multiple click events are available.
2. Define a Label attribute android:onclick= "method name" in the layout file, and then define a method in the. java file that the Android project calls this layout, the public method name (View v), Remember to public and have view parameters.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/B8/wKioL1WmeISQsg6SAAG2k_kZ2I0908.jpg "title=" click. PNG "alt=" Wkiol1wmeisqsg6saag2k_kz2i0908.jpg "/>
By looking at the source of the button's parent view, you can see that the onclick bottom uses the reflection principle, but does not use violent reflection, so define the method with public.
This article is from the "line of the World" blog, please be sure to keep this source http://4259297.blog.51cto.com/4249297/1675142
4 ways to read the Android day01-android button click event