代碼在onCreate! setContentView(R.layout.manual);
在if
之外時有效。但我搬到if
不能工作setContentView(R.layout.manual);
!爲什麼「setContentView」不能在if語句中工作?
的followign:
if (settings.getBoolean("my_first_time", true)) {
setContentView(R.layout.manual); // can not work
}
但Log.d("Comments1", "First time");
總是工作
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String PREFS_NAME = "MyPrefsFile";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
Log.d("Comments1", "First time");//this can be showed on logCat!
setContentView(R.layout.manual);// this can not work
// record the fact that the app has been started at least once
settings.edit().putBoolean("my_first_time", false).commit();
}
}
公共無效的onCreate(捆綁savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.manual);像這樣使用,因爲如果條件可能是錯誤的。 – 2013-05-08 05:22:49
發佈完整的onCreate代碼。 – 2013-05-08 05:25:38