Four click events of Android button button
In this article, four click events of Android button button are shared for your reference. The specific contents are as follows
The first: internal class implementation
1. Set the button attribute in XML first
2. Find the button
Button btn =(Button)findViewById(R.layout.button1)
3. Set a click event for the button
BTN. Setonclicklistener (New myclicklistener()) / / the clicklistener parameter is passed in, so we must define a parameter interface
4. Define a class to implement the interface type required by the button
The second is to use anonymous inner classes
1. Set the button attribute in XML first
2. Find the button
Button btn =(Button)findViewById(R.layout.button1);
3. Set a click event for the button
The third method: the onclicklistener interface implemented by the activity is applicable to multiple buttons
1. Set the button attribute in XML first
2. Find the button
3. Set a click event for the button
Fourth: declare onclick in XML
1. Set the button attribute in XML first
2. Find the button
Button btn =(Button)findViewById(R.layout.button1)
3. Declare a method. The method name is the same as the onclick attribute declared in the XML layout of the button you want to click
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.