Summary of five implementation methods of Android response event onclick method
In the development of Android, onclicklistener for click events has the following four implementation methods, and the appropriate usage can be selected according to the needs of the actual scene. The button button button is used as an example.
Method 1:
Suitable for scenarios: any scenario is common, but if there are multiple controls in an activity to implement the onclick method, it will appear code redundancy.
Method 2:
Suitable for scenario: it is suitable for multiple controls of the same type (such as button array) to implement onclick () method
Method 3:
Suitable for scenario: the same as method 2, there is little difference between the two
Method 4:
Suitable for scenario: it is suitable for different types of controls on the interface. This method implements the onclick method of all controls in one method, which looks relatively simple
Implement onclicklistener interface in activity:
Method 5:
Suitable for scenarios: General scenarios, especially when the logic of the click method of a control is complex.
Add Android: onclick = "method name" to the layout file. For some controls (such as textview), you need to be compatible with the old SDK API, and add Android: clickable = "true"
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.