Android naming format

Source: Internet
Author: User

  Strict line break

In General the next one ";" a line break

One row for the suggested function "{}"

Example:public void oosomething ()

  {

  ......

  }

Do not use:

Example:public void dosomething () {

  ....

  }

In fact, both ways can be, here do not make mandatory provisions.

It's best to use the first way, because it's also handy in this way in eclipse.

  Strict indentation

Use Tab Indent

Annotation indentation and Code indent alignment

  Strict comments

File, class, method, method parameter, variable, attribute are all to be commented

Each variable that has a meaning is written in a comment.

Comments for files and classes must include the following elements:

  Name,Description,Version,Date,Author , Change , Copyright

The main point to Remember is " follow the javaDoc standard ".

Example:/**

  */

The variable comment is written in front of //on it .

Cases:

  this is my name.

  /**

  */

  Private String Mname; //

This is not necessary, very troublesome, directly with a single-line comment.

There are comments are not recommended to put the back, put in front will be very neat.

  Location of the Declaration

Apply namespace Location

All frameworks define namespaces as a group, and custom and third-party namespaces are placed in another group.

  Import COM.ANDROID.INTERNAL.R;

  Import Com.android.internal.view.menu.MenuBuilder;

  Import Android.content.Context;

  Import android.content.res.Configuration;

  Import Android.content.res.TypedArray;

it 's all about the content.

  Import Android.graphics.Bitmap;

  Import Android.graphics.Canvas;

  Import Android.graphics.Interpolator;

  Import Sundy.android.demo;

class member Variable declaration location

All member variables should be declared at the top, using a blank line to separate them from the properties and methods.

  public class MyClass

  {

  int mnumber;

As far as possible in front of the class, do not interspersed to put

  String Mname;

  public void SomeMethod1 ()

  {}

  public void SomeMethod2 ()

  {}

  }

Local variable declaration location (variables in the method set)

Local variable declarations are placed at the top of the method

   declaring a variable with a Java predefined type instead of using the class name

Declaring a variable with a predefined type (keyword) without using the class name

use object instead of object

use int instead of Int32

Keywords are preferred using keyword

original link:http://www.maiziedu.com/wiki/android/pattern/

Android naming format

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.