zoukankan      html  css  js  c++  java
  • 几个有用的习惯

    1. 为了便于调试,所有类都定义TAG。并在所有方法(或者关键步骤开始)进行日志的记录。

    1. class TestService extends SuperClass{ 
    2.     private static final String TAG = "text.TestService"; 
    3.     // some code... 
    4.     private void method1(){ 
    5.         Log.i(TAG,"method1"); 
    6.         // some code... 
    7.     } 

    2. Activity中,很多控件都有click等事件,每一个控件都去注册显得代码比较乱。可以让Activity实现OnXXXXListener。在onXXX()方法中,统一处理。

    1. class MyActivity extends Activity implements OnClickListener{ 
    2.     // some code 
    3.     public void onCreate(Bundle savedInstanceState) { 
    4.         initComponent(); 
    5.         registerListenr(); 
    6.     } 
    7.     private void initComponent(){ 
    8.         mTextView = (TextView)findViewById(R.id.id1); 
    9.         mTextView2 = (TextView)findViewById(R.id.id2); 
    10.         // some code 
    11.     } 
    12.     private void registerListener(){ 
    13.         mTextView.setOnClickListener(this); 
    14.         mTextView.setOnClickListener(this); 
    15.     } 
    16.     private boolean onClick(View v,....) { 
    17.         switch(v.getId()){ 
    18.         case R.id.id1: 
    19.             break; 
    20.         case R.id.id2: 
    21.             break; 
    22.         default: 
    23.             Log.... 
    24.         } 
    25.     } 

    3. layout布局文件中,尽量通过include的方式进行复用。方便管理,节省时间,代码简洁一点。

    4. 使用style统一设置控件的属性。免得风格不统一,也节约代码。

    5. 发布正式包前,不使用混编。否则测试出bug后还是无法查看日志。你只能看到a.b.c....

  • 相关阅读:
    Using Resource File on DotNet
    C++/CLI VS CSharp
    JIT VS NGen
    [Tip: disable vc intellisense]VS2008 VC Intelisense issue
    UVa 10891 Game of Sum(经典博弈区间DP)
    UVa 10723 Cyborg Genes(LCS变种)
    UVa 607 Scheduling Lectures(简单DP)
    UVa 10401 Injured Queen Problem(简单DP)
    UVa 10313 Pay the Price(类似数字分解DP)
    UVa 10635 Prince and Princess(LCS N*logN)
  • 原文地址:https://www.cnblogs.com/awkflf11/p/4482564.html
Copyright © 2011-2022 走看看