Summary of several methods of Android clicking button to realize functions

The button control in Android should be regarded as a relatively simple control. However, its frequency of use is very high. Today, I summarize three common methods of clicking the button to realize its function.

1. Many times, when we use the button control, it is often used "once". At this time, for convenience, we generally use the method of anonymous inner class, as follows:

2. When there are multiple buttons or buttons are used many times, we need to use the method of binding listeners. In fact, there are several methods of binding listeners. However, I won't list them one by one here. After all, those methods are not common in practical applications.

Our general method is to implement the onclicklistener interface and its methods, as follows:

3. This is the simplest method. All we need to do is add a method and add an attribute for the button:

Then, we need to add the method declared in the attribute to the code:

1. Layout documents

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>