Code example for CheckBoxPreference

Methods: setDefaultValuesetKeysetTitle

0
        if (type == null || key == null || title == null)
            return; 
 
        Preference pref = null;
        if ("bool".equals(type)) { // We can add other types we want to support and handle the preference construction here
            pref = new CheckBoxPreference(this);
            pref.setKey(key);
            pref.setTitle(title);
            pref.setDefaultValue(Preferences.getBoolean(key, false));
        } 
 
        if (pref == null)
            return; 
 
        if (obj.optBoolean("restart")) {
            pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                @Override 
                public boolean onPreferenceChange(Preference preference, Object newValue) {
                    setResult(RESULT_OK);
                    return true; 
                }