Coding skills for medium-sized projects

Source: Internet
Author: User

In andriod, it is common to write dozens of java files with a slightly larger number of software. How to Write ideas without interrupting affects efficiency and patience.

Naming rules are defined by the team. The naming rules of each team are different, but they are the same-improving efficiency (Team consistency)

This is just for reference.

Package name: Name based on the role of each activity. For example, order settlement: account, address management: addr. Several main activities have several different packages.

Name the java file under the package

Main activity file package name_activity

Sub-file: Package name_function package name_adapter


650) this. width = 650; "title =" zhu.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0641434234-0.jpg "/>

Project Public package name:

If there is a jump between activities, we recommend that you create a "intent" package name and create an IntentsUnits. java file under the package.

All the objects to be redirected are written under this file.


package com.intent;import com.addr.Addr_list;import com.item_intent.Item_activity;import android.app.Activity;import android.content.Intent;import android.sax.StartElementListener;public class IntentsUnits {public static void toAddrList(Activity activity){Intent intent = new Intent();intent.setClass(activity, Addr_list.class);activity.startActivity(intent);}public static void toIntentActivity(Activity activity, String type){Intent intent = new Intent();intent.setClass(activity, Item_activity.class);intent.putExtra("type", type);activity.startActivity(intent);}}

Create a sqlitedb package name for a database. The package name is "Database Name DB".

650) this. width = 650; "title =" db.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0641433b7-1.jpg "/>

Create a "projectConstant" package name with a constant, and create a ProjectConstant under the package name. java, and then write all the constants related to the project here, not in the string file under the resource, sometimes it is difficult to use or modify. Especially when databases are used in projects.

Package com. projectConstant; import android. r. string; import android. OS. environment; public class ProjectConstant {// file or dirpublic static String ProjectDir = Environment. getExternalStorageDirectory (). getPath () + "/xinyu_school/"; public static String projectDBDir = ProjectDir + "database"; // database folder name public static String projectImageDir = ProjectDir + "image "; // The image folder // The typepublic static String HISTORYTYPE_BUYING = "1"; // The public static String HISTORYTYPE_BOUGHT = "2 "; // you have purchased public static String HISTORYTYPE_STORE = "3"; // Add to favorites // you do not need to pay attention to the public static String projectDBDirName = "/xinyu_school/database /"; // you do not need to worry about it here // database at sdcardpublic static String DB_PRODUCT = "product_db.db "; // product productParent picturename productname price number // happy Bar path roast pig 30, 10 public static String DB_PRODUCTTABLE = "product"; public static String DB_PARENT = "parent "; public static String DB_PICTURENAME = "picturename"; public static String DB_PRODUCTNAME = "productname"; public static String DB_PRICE = "price"; public static String DB_NUMBER = "number "; public static String DB_TOADDR = "ToAddr_db.db"; public static String DB_TOADDR_TABLE = "ToAddr"; public static String DB_TONAME = "toname"; public static String DB_TOADDRESS = "toaddress "; public static String DB_TOTEL = "totel"; public static String DB_TOCHECKED = "checked"; public static String DB_TODEFAULT = "defaulted"; public static String DB_HISTORY = "history. db "; public static String DB_HSTRYTABLE =" historytable "; public static String DB_HISTORY_TYPE =" type "; public static String DB_CLIENT_ID =" admin ";}

Class package name:Some data classes must be made before the work process. Therefore, we need to create an object package ProjectClass. The low file names are named based on each class.

650) this. width = 650; "title =" class.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/064143D04-2.jpg "/>

Name the file in layout according to the layout corresponding to the activity function.

650) this. width = 650; "title =" layout.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0641434252-3.jpg "/>


Key:The name of the xml internal control under layout, and the name of the file under drawable. The generated IDs are all under R. id:

Layout_xml name_function of the xml space in layout, for example, layout_client_addr_tel in address management

The name of the file under drawable can be used with the control function of the xml name_to which draw _ belongs. For example, draw_client_addr_tel.

Finally:In each java file, the "my control function" is used to facilitate the index handle.

For example

public class ClientActivity extends Activity {    TextView myAddr;    Button myAddrButton;    TextView myHisBuy;    Button mymyHisBuyButton;    TextView myStore;    Button myStoreButton;    ToAddrDB myToAddrDB;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.clientinfo);        init();    }



Also attached previously written ecshop shop prototype code http://pan.baidu.com/share/link? Author ID = 1333309535 & uk = 2065228996. This Code involves almost 30% of what I learned. The coding style and content in it have some learning value. After downloading the file, read "Description .txt ". UTF-8 encoded.

This article is from the "lilin9105" blog, please be sure to keep this source http://7071976.blog.51cto.com/7061976/1232357

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.