1. 为了便于调试,所有类都定义TAG。并在所有方法(或者关键步骤开始)进行日志的记录。
class TestService extends SuperClass{
private static final String TAG = "text.TestService";
// some code...
private void method1(){
Log.i(TAG,"method1");
// some code...
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
2. Activity中,很多控件都有click等事件,每一个控件都去注册显得代码比较乱。可以让Activity实现OnXXXXListener。在onXXX()方法中,统一处理。
class MyActivity extends Activity implements OnClickListener{
// some code
public void onCreate(Bundle savedInstanceState) {
initComponent();
registerListenr();
}
private void initComponent(){
mTextView = (TextView)findViewById(R.id.id1);
mTextView2 = (TextView)findViewById(R.id.id2);
// some code
}
private void registerListener(){
mTextView.setOnClickListener(this);
mTextView.setOnClickListener(this);
}
private boolean onClick(View v,....) {
switch(v.getId()){
case R.id.id1:
break;
case R.id.id2:
break;
default:
Log....
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
3. layout布局文件中,尽量通过include的方式进行复用。方便管理,节省时间,代码简洁一点。
4. 使用style统一设置控件的属性。免得风格不统一,也节约代码。
5. 发布正式包前,不使用混编。否则测试出bug后还是无法查看日志。你只能看到a.b.c....
只列了一些我自己整理的东西,viewholder之类的,就没列了
暂时想到这么多。。。欢迎补充