大多数 Android 代码示例都像下面的示例 2 那样完成,为什么它比示例 1 中显示的要好得多?
示例 1
class TestActivity extends Activity() {
HelperClass helperClass = new HelperClass();
EditText extiText = (EditText) findViewById(R.id.editText1);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
示例 2
class TestActivity extends Activity() {
HelperClass helperClass;
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
helperClass = new HelperClass();
editText = (EditText) findViewById(R.id.editText1);
}
}