Android naming rules

Source: Internet
Author: User

I. Android coding specifications

1. the java code does not contain Chinese characters. A maximum of Chinese characters can appear in comments.

2. Local variable naming and static member variable naming

It can only contain letters. The first letter of a word must be in upper case and the other letters must be in lower case.

3. Constant naming

It can only contain letters and _. All letters are in uppercase. Words are separated _.

4. Name the id in layout

Naming mode: view abbreviation _ module name_view logical name

The abbreviated view details are as follows:

LayoutView: lv

RelativeView: rv

TextView: TV

ImageView: iv

ImageButton: im

Button: btn

5. Name the view variable in the activity

Naming mode: Logical name + view abbreviation

Suggestion: If the layout file is complex, we recommend that you divide layout into multiple modules. Each module defines a moduleViewHolder whose member variables contain the view

6. id naming in strings. xml

Naming mode: activity name_function module name_logic name/activity name_logic name/common _ logic name

In strings. xml, use activity name annotations to differentiate the file content.

7. Name the image in drawable

Naming mode: activity name_logical name/common _ logical name

7. styles. xml: extract the styles that are repeatedly reproduced in layout into general style components and put them in styles. xml;

8. Use layer-list and selector

9. Split images into multiple reusable images as much as possible

10. What the server can achieve is not to be placed on the client.

11. Exercise caution when referencing a third-party library to avoid using a large third-party library, resulting in a large client package.

12. Handle global application exceptions and errors and send the errors to the server by email.

13. process image. 9

14. Exercise caution when using static variables to share Interfaces

15. Log (system name module Name Interface Name, detailed description)

16. unit test (logical test and Interface Test)

17. Do not reuse the handler of the parent class. The handler of the corresponding class should not be used by its subclass. Otherwise, the message. what conflict will occur.

18. process all logic in a View. OnClickListener in the activity

19. Use % 1 $ s in strings. xml for character string wildcard

20. If multiple activities contain common UI processing, you can extract a CommonActivity and call the common part for processing. Other activities only need to inherit it.

21. When you use button + activitgroup to implement the tab effect, use Button. setSelected (true) to make sure that the button is in the selected State and that the current activity of activitygroup corresponds to the button.

22. If a common component is developed, prefix the file name in the drawable/layout/menu/values directory to avoid conflicts.

23. data must be validated, such

The numeric type must have a default value if the conversion fails;

Whether the server response data is valid

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.