Code example for PreferenceCategory

Methods: setTitle, addPreference

0
	private PreferenceScreen createPreferenceHierarchy() {
		// Root 
		PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
 
		// Launch preferences 
		PreferenceCategory syncPrefCat = new PreferenceCategory(this);
		syncPrefCat.setTitle("Sync accounts");
		root.addPreference(syncPrefCat);
 
		Preference syncDropboxSwitchPref = null;
		int currentapiVersion = android.os.Build.VERSION.SDK_INT;
		if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
			syncDropboxSwitchPref = createSyncDropboxSwitchPref(syncPrefCat);
		} else { 
			syncDropboxSwitchPref = new CheckBoxPreference(this);
		} 
		syncDropboxSwitchPref.setKey("sync_dropbox");
		syncDropboxSwitchPref.setTitle("Dropbox");
		syncDropboxSwitchPref.setSummary(this.dropboxHelper.isLoggedIn() ? "Linked" : "Not linked");
		syncDropboxSwitchPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				doSyncDropbox((Boolean) newValue);
				return true; 
			} 
		}); 
		syncPrefCat.addPreference(syncDropboxSwitchPref);
 
		return root;
	} 
 
	@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)