应用程序的setContentView

时间:2013-05-26 12:54:11

标签: android

所以我在设置中有复选框来输入不同的xml  <CheckBoxPreference android:title="Full Screen" android:defaultValue="false" android:key="checkbox3" 如果没有选中checkbox3则使用setContentView(1st xml)如果选中setContentView(second xml)

SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean samples = getPrefs.getBoolean("checkbox3", true);
    if(samples==false)
    setContentView(R.layout.activity_main);
    else{
        setContentView(R.layout.fullscreen);
    }

我的问题是checkbox的默认值是false,所以当你第一次运行应用程序时,它应该是setContentView(R.layout.activity_main);但它进入setContentView(R.layout.activity_main);即使它在设置中是“假的”。

2 个答案:

答案 0 :(得分:2)

boolean samples = getPrefs.getBoolean("checkbox3", true);更改为boolean samples = getPrefs.getBoolean("checkbox3", false);

您已将默认值设置为true而非false

答案 1 :(得分:1)

根据您的代码,您错误地将复选框的默认值设为:

boolean samples = getPrefs.getBoolean("checkbox3", true); 

将其更改为

boolean samples = getPrefs.getBoolean("checkbox3", false); 

你很好