下面列出了android.preference.MultiSelectListPreference#setDefaultValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
// Load the preferences screen from an XML resource
addPreferencesFromResource(R.xml.preferences);
String[] pickerKeys = { PreferenceUtils.TRUST_STORE_LOCATION_KEY, PreferenceUtils.KEY_STORE_LOCATION_KEY };
for (String key: pickerKeys) {
FilechoserEditTextPreference picker = (FilechoserEditTextPreference) findPreference(key);
picker.setFragment(this);
}
PreferenceScreen pref = (PreferenceScreen) findPreference("pref_security");
if (SUPPORTED_CIPHER_SUITES.isEmpty()) {
SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
ENABLED_CIPHER_SUITES.addAll(Arrays.asList(ssf.getDefaultCipherSuites()));
SUPPORTED_CIPHER_SUITES.addAll(Arrays.asList(ssf.getSupportedCipherSuites()));
}
MultiSelectListPreference ciphersPref = (MultiSelectListPreference) findPreference(PreferenceUtils.ENABLED_CIPHER_SUITES_KEY);
ciphersPref.setDefaultValue(ENABLED_CIPHER_SUITES.toArray(new String[ENABLED_CIPHER_SUITES.size()]));
ciphersPref.setEntryValues(SUPPORTED_CIPHER_SUITES.toArray(new String[SUPPORTED_CIPHER_SUITES.size()]));
ciphersPref.setEntries(SUPPORTED_CIPHER_SUITES.toArray(new String[SUPPORTED_CIPHER_SUITES.size()]));
} catch(Throwable t) {
t.printStackTrace();
}
}
/**
* Helper Class to setup the default Unit Type preference list in code
*/
private void setUpUnitTypePrefs() {
PreferenceScreen screen = getPreferenceScreen();
MultiSelectListPreference listPref = new MultiSelectListPreference(super.getActivity());
listPref.setOrder(0);
listPref.setDialogTitle(R.string.unit_select_title);
listPref.setKey(UNIT_TYPE_PREF_KEY);
listPref.setSummary(R.string.unit_select_summary);
listPref.setTitle(R.string.unit_select_title);
listPref.setEntries(getUnitTypeNameArray(getResources()));
String[] keyArray = getUnitTypeKeyArray(getResources());
listPref.setEntryValues(keyArray);
final Set<String> result = new HashSet<>();
Collections.addAll(result, keyArray);
listPref.setDefaultValue(result);
screen.addPreference(listPref);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
String[] selections = getResources().getStringArray(R.array.sources_news_values);
Set<String> selectionSet = new HashSet<String>();
selectionSet.addAll(Arrays.asList(selections));
MultiSelectListPreference multiSelectPref = new MultiSelectListPreference(getActivity());
multiSelectPref.setKey("multi_pref");
multiSelectPref.setTitle(CHOIX_DES_SOURCES);
multiSelectPref.setEntries(R.array.sources_news);
multiSelectPref.setEntryValues(R.array.sources_news_values);
multiSelectPref.setDefaultValue(selectionSet);
getPreferenceScreen().addPreference(multiSelectPref);
// Make sure default values are applied. In a real app, you would
// want this in a shared function that is used to retrieve the
// SharedPreferences wherever they are needed.
// PreferenceManager.setDefaultValues(getActivity(),R.xml.advanced_preferences, false);
// Load the preferences from an XML resource
}