Four ways to write button click events and commonly used layouts in Android

Source: Internet
Author: User

1. The way of anonymous inner class

2, create a class implementation Onclicklistener, implement the OnClick method, set the control to pass a class object when clicked

3, let the current class implement Onclicklistener, set the control click event when passing a this. This approach is suitable for more buttons, generally in the company's use of the way

4, in the layout file for the control to add an OnClick property, in the layout of the activity to write an OnClick property value is the name of the method, to Publick, pass a view type of parameters, relatively suitable for doing simple test.

Layout:

1. Linear layout (vertical, horizontal): LinearLayout

Property:

Gravity: The alignment of the child control relative to the current control's alignment method.

2. Relative layout: relativelayout

3. Frame layout:

4. Table layout:

Four ways to write button click events and commonly used layouts in Android

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.