Simple example of button event monitoring developed by Android
This article illustrates the usage of button event listening developed by Android. Share with you for your reference. The details are as follows:
There are several ways to listen to events:
1. Declare an ordinary class, implement the onclicklistener interface, and then new an object of this class in setonclicklistener of button.
2. Use anonymous inner classes to directly
The difference between the above two methods is that one is an ordinary class and the other is an anonymous inner class. The advantage of anonymous inner classes is that there is no need to define a class elsewhere and answer here. Write the required class logic directly where it is used.
The advantage of ordinary classes is that they can be reused.
Sometimes you can let the activity directly implement the onclicklistener interface and let it act as a listener. At this time, you only need to write this in the setonclicklistener parameter.
I hope this article will be helpful to your Android program design.