2-10 four ways for Android buttons to listen to events (3)

Source: Internet
Author: User

1. There are four methods to set the listener for buttion in Android:

Directly implement the onclicklistener method for the activity, and then override its onclick method.

Use an internal class to create a class to implement the onclicklistener method.

Use a listener

Using anonymous internal classes is the most common method, but it is better to use the first method if there are many listening events. That is faster!

2. A very small problem to be aware of when alertdialog is defined

When instantiating alertdialog. Builder = new alertdialog. Builder (this); pay attention to the parameters in the brackets.

If it is instantiated in an anonymous internal class, you must add. This to the project file name! 10 million

Do not use the getapplicationcontext () method, because what is obtained!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.