代码在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