本文整理汇总了Java中android.preference.MultiSelectListPreference.setValues方法的典型用法代码示例。如果您正苦于以下问题:Java MultiSelectListPreference.setValues方法的具体用法?Java MultiSelectListPreference.setValues怎么用?Java MultiSelectListPreference.setValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.MultiSelectListPreference
的用法示例。
在下文中一共展示了MultiSelectListPreference.setValues方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupWeekDaysPref
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private void setupWeekDaysPref() {
mPrefWeekDays = (MultiSelectListPreference) findPreference(PREF_KEY_QH_WEEKDAYS);
String[] days = new DateFormatSymbols(Locale.getDefault()).getWeekdays();
CharSequence[] entries = new CharSequence[7];
CharSequence[] entryValues = new CharSequence[7];
for (int i = 1; i <= 7; i++) {
entries[i - 1] = days[i];
entryValues[i - 1] = String.valueOf(i);
}
mPrefWeekDays.setEntries(entries);
mPrefWeekDays.setEntryValues(entryValues);
if (mPrefs.getStringSet(PREF_KEY_QH_WEEKDAYS, null) == null) {
Set<String> value = new HashSet<String>(Arrays.asList("2", "3", "4", "5", "6"));
mPrefs.edit().putStringSet(PREF_KEY_QH_WEEKDAYS, value).commit();
mPrefWeekDays.setValues(value);
}
}
示例2: setupElmCmdSelection
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
/**
* set up protocol selection
*/
void setupElmCmdSelection()
{
MultiSelectListPreference pref =
(MultiSelectListPreference) findPreference(ELM_CMD_DISABLE);
ElmProt.CMD[] values = ElmProt.CMD.values();
HashSet<String> selections = new HashSet<String>();
CharSequence[] titles = new CharSequence[values.length];
CharSequence[] keys = new CharSequence[values.length];
int i = 0;
for (ElmProt.CMD cmd : values)
{
titles[i] = cmd.toString();
keys[i] = cmd.toString();
if(!cmd.isEnabled()) selections.add(cmd.toString());
i++;
}
// set enries and keys
pref.setEntries(titles);
pref.setEntryValues(keys);
pref.setValues(selections);
}
示例3: loadGroup
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private void loadGroup() {
// Consider adding more features here, such as those in Track and TrackPreferenceFragment
name = (EditTextPreference) findPreference("name");
name.setText(group.getName());
name.setSummary(group.getName());
description = (EditTextPreference) findPreference("description");
description.setText(group.getDescription());
description.setSummary(group.getDescription());
mTracksPref = (MultiSelectListPreference) findPreference("tracks");
mTracksPref.setValues(getTrackIdsForGroupAsSet(group.getId()));
mTracksPref.setEntries(getAllTrackNamesAsCharSeq());
mTracksPref.setEntryValues(getAllTrackIdsAsCharSeq());
mTracksPref.setSummary(getTrackNamesForSummary());
}
示例4: setValue
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void setValue(@NonNull Preference preference,
@NonNull ConfigBase.Option option,
@NonNull Object value) {
int mode = (int) value;
String[] values = new String[Integer.bitCount(mode)];
for (int i = 1, j = 0; j < values.length; i <<= 1) {
if (Operator.bitAnd(mode, i)) {
values[j++] = Integer.toString(i);
}
}
Set<String> valuesSet = new HashSet<>();
Collections.addAll(valuesSet, values);
MultiSelectListPreference mslp = (MultiSelectListPreference) preference;
mslp.setValues(valuesSet);
}
示例5: setupPidSelection
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
/**
* set up selection for PIDs
*/
void setupPidSelection()
{
MultiSelectListPreference itemList =
(MultiSelectListPreference) findPreference(KEY_DATA_ITEMS);
// collect data items for selection
items = ObdProt.dataItems.getSvcDataItems(ObdProt.OBD_SVC_DATA);
HashSet<String> selections = new HashSet<String>();
CharSequence[] titles = new CharSequence[items.size()];
CharSequence[] keys = new CharSequence[items.size()];
// loop through data items
int i = 0;
for (EcuDataItem currItem : items)
{
titles[i] = currItem.label;
keys[i] = currItem.toString();
selections.add(currItem.toString());
i++;
}
// set enries and keys
itemList.setEntries(titles);
itemList.setEntryValues(keys);
// if there is no item selected, mark all as selected
if (itemList.getValues().size() == 0)
{
itemList.setValues(selections);
}
}
示例6: 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);
}
示例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);
}