four ways to read Android Click events:
1. Implement the Onclicklistener interface in the form of an internal class. Defining Click Events
Class mainactivity extents activity{//... private class MyListener implements Onclicklistener{public void Onclick (View v) {// ... Click the response of the event}}}
2. Using Anonymous internal classes
?? Disadvantage: Too many anonymous internal classes are required if there are too many click events
Class mainactivity extents activity{protected void onCreate (...) {//The Bt_call.setonclicklistener (new onclicklistener{public void Onclick (View v) {//...) is implemented as an anonymous inner class. Click the response of the event}});}}
3. The mainactivity implementation of the Onclicklistener interface, the actual development of a very frequent use of the wording
?? Strengths: Able to solve the problem of Method 2
Class mainactivity extents Activity implements onclicklistener{protected void OnCreate (...) {// ...} /*** Click event */public void OnClick (View v) {//based on different Id to determine what action switch (V.getid ()) {case r.id.bt_call:callphone ();//define function, Make a call to break;
4. The method of binding a click event in the configuration file is not used frequently
Activity_main.xml:
<button android:onclick= "Callphone"//Bind the button's Click event. Will proactively find the method in the Activity .../>
Mainactivity.java:
Class mainactivity extents Activity {/*** Click event. In this case the method must take the parameter view v*/public void Callphone (view v) {//...}}
Android Notes---Four ways to click events