0
大部分Android代碼的每個例子都是像下面的例子2那樣完成的,爲什麼它比示例1中顯示的好得多?在onCreate內部與其外部實例化相比。爲什麼?
例如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);
}
}
是的,我忘了這一點,該佈局文件必須在EDITTEXT之前加載的事實被加載 – Kevik
是的,你是對的.. –