코드가 onCreate에 있습니다! setContentView(R.layout.manual);
이 if
외부에있는 경우 작동합니다. 그러나 나는 setContentView(R.layout.manual);
로 if
로 움직일 수 없다!if 문에서 "setContentView"가 작동하지 않는 이유는 무엇입니까?
한 아래와 같은 :
if (settings.getBoolean("my_first_time", true)) {
setContentView(R.layout.manual); // can not work
}
그러나 Log.d("Comments1", "First time");
항상
settings.getBoolean("my_first_time", true)
사실이 반환되지 않기 때문에
@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); 조건이 거짓 일 수 있기 때문에 그렇게 사용하십시오. –
전체 코드를 게시하십시오. –