本文整理汇总了Java中android.preference.MultiSelectListPreference.setOnPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java MultiSelectListPreference.setOnPreferenceChangeListener方法的具体用法?Java MultiSelectListPreference.setOnPreferenceChangeListener怎么用?Java MultiSelectListPreference.setOnPreferenceChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.MultiSelectListPreference
的用法示例。
在下文中一共展示了MultiSelectListPreference.setOnPreferenceChangeListener方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.custom_prefs);
// This sample app uses shared preferences to maintain app restriction settings. Your app
// can use other methods to maintain the settings.
mBooleanPref = (CheckBoxPreference) findPreference(KEY_BOOLEAN_PREF);
mChoicePref = (ListPreference) findPreference(KEY_CHOICE_PREF);
mMultiPref = (MultiSelectListPreference) findPreference(KEY_MULTI_PREF);
mBooleanPref.setOnPreferenceChangeListener(this);
mChoicePref.setOnPreferenceChangeListener(this);
mMultiPref.setOnPreferenceChangeListener(this);
setRetainInstance(true);
}
示例2: bindPreferenceSummaryToValue
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private static void bindPreferenceSummaryToValue(MultiSelectListPreference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getStringSet(preference.getKey(), null));
}
示例3: onCreate
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
mRealm = Realm.getDefaultInstance();
mCurrentPhoto = findPreference("current_photo");
mNextPhoto = findPreference("next_photo");
mLogin = findPreference("login");
mCategories = (MultiSelectListPreference) findPreference("categories");
mInterval = (ListPreference) findPreference("update_interval");
mNextPhoto.setOnPreferenceClickListener(this);
mLogin.setOnPreferenceClickListener(this);
findPreference("clear_cache").setOnPreferenceClickListener(this);
findPreference("contact").setOnPreferenceClickListener(this);
mCategories.setOnPreferenceChangeListener(this);
mInterval.setOnPreferenceChangeListener(this);
findPreference("enable").setOnPreferenceChangeListener(this);
findPreference("use_only_wifi").setOnPreferenceChangeListener(this);
setCategoriesSummary(mCategories.getValues());
mInterval.setSummary(mInterval.getEntry());
findPreference("version").setSummary(BuildConfig.VERSION_NAME);
if (!Utils.supportsParallax(getActivity())) {
((PreferenceCategory) findPreference("settings"))
.removePreference(findPreference("use_parallax"));
}
WallpaperApplication.getBus().register(this);
onUserUpdated(new UserUpdatedEvent());
}
示例4: addAccountsPreference
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private void addAccountsPreference() {
final String[] accounts = GmailExtension.getAllAccountNames(this);
Set<String> allAccountsSet = new HashSet<String>();
allAccountsSet.addAll(Arrays.asList(accounts));
MultiSelectListPreference accountsPreference = new MultiSelectListPreference(this);
accountsPreference.setKey(GmailExtension.PREF_ACCOUNTS);
accountsPreference.setTitle(R.string.pref_gmail_accounts_title);
accountsPreference.setEntries(accounts);
accountsPreference.setEntryValues(accounts);
accountsPreference.setDefaultValue(allAccountsSet);
mFragment.getPreferenceScreen().addPreference(accountsPreference);
Preference.OnPreferenceChangeListener accountsChangeListener
= new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int numSelected = 0;
int numTotal = accounts.length;
try {
//noinspection unchecked
Set<String> selectedAccounts = (Set<String>) value;
if (selectedAccounts != null) {
numSelected = selectedAccounts.size();
}
} catch (ClassCastException ignored) {
}
preference.setSummary(getResources().getQuantityString(
R.plurals.pref_gmail_accounts_summary_template,
numTotal, numSelected, numTotal));
return true;
}
};
accountsPreference.setOnPreferenceChangeListener(accountsChangeListener);
accountsChangeListener.onPreferenceChange(accountsPreference,
PreferenceManager
.getDefaultSharedPreferences(this)
.getStringSet(accountsPreference.getKey(), allAccountsSet));
}
示例5: onCreate
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SettingsActivityComponent cmp = DaggerService.getDaggerComponent(getActivity());
cmp.inject(this);
mSettings.setCached(true);
addPreferencesFromResource(R.xml.prefs_service);
runWhen = (ListPreference) findPreference(ServiceSettings.RUN_WHEN);
runWhen.setPersistent(false);
runWhen.setValue(mSettings.runWhen());
runWhen.setOnPreferenceChangeListener(this);
onlyOnWifi = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_WIFI);
onlyOnWifi.setPersistent(false);
onlyOnWifi.setChecked(mSettings.onlyOnWifi());
onlyOnWifi.setOnPreferenceChangeListener(this);
wifiNetwork = (MultiSelectListPreference) findPreference(ServiceSettings.WIFI_NETWORKS);
wifiNetwork.setPersistent(false);
String[] ssids = getWifiNetworks();
wifiNetwork.setEntries(ssids);
wifiNetwork.setEntryValues(ssids);
wifiNetwork.setValues(mSettings.allowedWifiNetworks());
wifiNetwork.setOnPreferenceChangeListener(this);
onlyCharging = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_CHARGING);
onlyCharging.setPersistent(false);
onlyCharging.setChecked(mSettings.onlyWhenCharging());
onlyCharging.setOnPreferenceChangeListener(this);
catBetween = (PreferenceCategory) findPreference("cat_between");
hideShowRunWhenCategories(mSettings.runWhen());
scheduleStart = (TimePreference) findPreference(ServiceSettings.RANGE_START);
scheduleStart.setPersistent(false);
scheduleStart.setValue(mSettings.getScheduledStartTime());
scheduleStart.setOnPreferenceChangeListener(this);
scheduleEnd = (TimePreference) findPreference(ServiceSettings.RANGE_END);
scheduleEnd.setPersistent(false);
scheduleEnd.setValue(mSettings.getScheduledEndTime());
scheduleEnd.setOnPreferenceChangeListener(this);
exportConfig = findPreference("export");
exportConfig.setOnPreferenceClickListener(this);
importConfig = findPreference("import");
importConfig.setOnPreferenceClickListener(this);
}
示例6: addAccountsPreference
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private void addAccountsPreference() {
final String[] accounts = GmailExtension.getAllAccountNames(this);
Set<String> allAccountsSet = new HashSet<String>();
allAccountsSet.addAll(Arrays.asList(accounts));
MultiSelectListPreference accountsPreference = new MultiSelectListPreference(this);
accountsPreference.setKey(GmailExtension.PREF_ACCOUNTS);
accountsPreference.setTitle(R.string.pref_gmail_accounts_title);
accountsPreference.setEntries(accounts);
accountsPreference.setEntryValues(accounts);
accountsPreference.setDefaultValue(allAccountsSet);
getPreferenceScreen().addPreference(accountsPreference);
Preference.OnPreferenceChangeListener accountsChangeListener
= new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int numSelected = 0;
int numTotal = accounts.length;
try {
//noinspection unchecked
Set<String> selectedAccounts = (Set<String>) value;
if (selectedAccounts != null) {
numSelected = selectedAccounts.size();
}
} catch (ClassCastException ignored) {
}
preference.setSummary(getResources().getQuantityString(
R.plurals.pref_gmail_accounts_summary_template,
numTotal, numSelected, numTotal));
return true;
}
};
accountsPreference.setOnPreferenceChangeListener(accountsChangeListener);
accountsChangeListener.onPreferenceChange(accountsPreference,
PreferenceManager
.getDefaultSharedPreferences(this)
.getStringSet(accountsPreference.getKey(), allAccountsSet));
}
示例7: bindPreferenceSummaryToValue
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private static void bindPreferenceSummaryToValue(MultiSelectListPreference preference,
List<Account> accounts) {
int len = accounts.size();
CharSequence[] entries = new CharSequence[len];
CharSequence[] entryValues = new CharSequence[len];
Set<String> defaultValue = new HashSet<String>();
Set<String> savedUuids = PreferenceManager.getDefaultSharedPreferences(
preference.getContext()).getStringSet(preference.getKey(), null);
// Populate MultiSelectListPreference with entries for all available accounts
int i = 0;
for (Account account : accounts) {
defaultValue.add(account.uuid);
entries[i] = account.name;
entryValues[i] = account.uuid;
i++;
}
preference.setEntries(entries);
preference.setEntryValues(entryValues);
// Check currently selected accounts
Set<String> selectedAccounts;
if (savedUuids == null) {
// Select all accounts if there was no saved configuration
selectedAccounts = defaultValue;
} else {
// Clear out accounts that no longer exist
selectedAccounts = new HashSet<String>(savedUuids);
for (Iterator<String> iter = selectedAccounts.iterator(); iter.hasNext(); ) {
String accountUuid = iter.next();
if (!defaultValue.contains(accountUuid)) {
iter.remove();
}
}
}
preference.setValues(selectedAccounts);
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, selectedAccounts);
preference.setEnabled(true);
}