public void updateNotificationPreference(ListPreference listpref) { CharSequence[] entries = listpref.getEntries(); CharSequence[] values = listpref.getEntryValues(); for (int i = 0; i < entries.length; i++) { int value = Integer.parseInt(values[i].toString()); if (entries[i].toString().contains("%d")) { entries[i] = String.format(entries[i].toString(), value); } } listpref.setEntries(entries); listpref.setSummary(listpref.getEntry().toString()); }
public boolean onPreferenceChange(Preference preference, Object newValue) { final String summary = newValue.toString(); int index = mNotifyClass.findIndexOfValue(summary); mNotifyClass.setSummary(mNotifyClass.getEntries()[index]); mNotifyClass.setValue(summary); return false; } });
/** * Show the preference value in the preference summary field. */ @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { final String summary = newValue.toString(); final int index = mPrefView.findIndexOfValue(summary); mPrefView.setSummary(mPrefView.getEntries()[index]); mPrefView.setValue(summary); return false; } }
public boolean onPreferenceChange(Preference preference, Object newValue) { final String summary = newValue.toString(); int index = mSyncClass.findIndexOfValue(summary); mSyncClass.setSummary(mSyncClass.getEntries()[index]); mSyncClass.setValue(summary); return false; } });
public boolean onPreferenceChange(Preference preference, Object newValue) { final String summary = newValue.toString(); int index = mDisplayClass.findIndexOfValue(summary); mDisplayClass.setSummary(mDisplayClass.getEntries()[index]); mDisplayClass.setValue(summary); return false; } });
public boolean onPreferenceChange(Preference preference, Object newValue) { final String summary = newValue.toString(); int index = mPushClass.findIndexOfValue(summary); mPushClass.setSummary(mPushClass.getEntries()[index]); mPushClass.setValue(summary); return false; } });
public ListPreferenceAssert hasEntries(CharSequence... entries) { isNotNull(); CharSequence[] actualEntries = actual.getEntries(); assertThat(actualEntries) // .overridingErrorMessage("Expected entries <%s> but was <%s>.", entries, actualEntries) // .isEqualTo(entries); return this; }
private void updateSummary(ListPreference pref, String value) { if (value==null || value.length()==0) { pref.setSummary(R.string.missing_text); } else { int index=pref.findIndexOfValue(value); if (index==-1) { pref.setSummary(R.string.missing_text); } else { pref.setSummary(pref.getEntries()[index]); } } } }
@Test public void shouldHaveEntries() { CharSequence[] entries = { "this", "is", "only", "a", "test" }; assertThat(listPreference.getEntries()).isNull(); listPreference.setEntries(entries); assertThat(listPreference.getEntries()).isSameAs(entries); }
@Test public void shouldSetEntriesByResourceId() { assertThat(listPreference.getEntries()).isNull(); listPreference.setEntries(R.array.greetings); assertThat(listPreference.getEntries()).isNotNull(); }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference instanceof ListPreference) { //把preference这个Preference强制转化为ListPreference类型 ListPreference listPreference = (ListPreference) preference; //获取ListPreference中的实体内容 CharSequence[] entries = listPreference.getEntries(); //获取ListPreference中的实体内容的下标值 int index = listPreference.findIndexOfValue((String) newValue); //把listPreference中的摘要显示为当前ListPreference的实体内容中选择的那个项目 listPreference.setSummary(entries[index]); } // 设置hosts if (preference.getKey().equals("system_host")) { DeviceUtils.changeHost(((SysApplication)getApplication()).proxy,newValue.toString()); hostPreference.setSummary(getHost()); } // 重启抓包进程 if (preference.getKey().equals("enable_filter")) { Toast.makeText(this, "重启程序后生效", Toast.LENGTH_SHORT).show(); // ((SysApplication)getApplication()).stopProxy(); // ((SysApplication)getApplication()).startProxy(); // Toast.makeText(this, "抓包进程重启完成", Toast.LENGTH_SHORT).show(); } return true; }
CharSequence entry = m_updateList.getEntries()[index]; m_updateList.setSummary(entry);
public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; } };
private void preSelectListForBackward() { final ListPreference itemList = (ListPreference) findPreference("passSetting"); //remove other option if (Build.VERSION.SDK_INT < 21) { itemList.setEntries(itemList.getEntries()); itemList.setEntryValues(itemList.getEntryValues()); } if (itemList != null) { switch (G.protectionLevel()) { case "p0": itemList.setValueIndex(0); break; case "p1": itemList.setValueIndex(1); break; case "p2": itemList.setValueIndex(2); break; case "p3": itemList.setValueIndex(3); break; case "Disable": itemList.setValueIndex(0); break; default: itemList.setValueIndex(0); break; } } }
final ListPreference list = (ListPreference) preference; lista.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { int index = list.findIndexOfValue(newValue.toString()); if (index != -1) { Toast.makeText(getBaseContext(), list.getEntries()[index], Toast.LENGTH_LONG).show(); } return true; } });
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { ListPreference list = (ListPreference) preference; int idx = list.findIndexOfValue((String) newValue); if (idx == -1) { return false; } preference.setSummary(list.getEntries()[idx]); return true; } });
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { // Set summary with the display text of the item and a description of the preference ListPreference orientationListPreference = (ListPreference)preference; // Pull the display string from the list preference rather than simply using the key value int newValueIndex = orientationListPreference.findIndexOfValue((String)newValue); String newPreferenceDisplayValue = orientationListPreference.getEntries()[newValueIndex].toString(); preference.setSummary(newPreferenceDisplayValue + ".\n" + getResources().getString(R.string.prefs_ui_orientation_summary)); return true; } });
@Override public boolean onPreferenceChange(Preference preference, Object value) { String textValue = value.toString(); ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(textValue); CharSequence[] entries = listPreference.getEntries(); if(index >= 0) Toast.makeText(preference.getContext(), entries[index], Toast.LENGTH_LONG); return true; }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { int index = ((ListPreference) preference).findIndexOfValue(newValue.toString()); String entry = (String) ((ListPreference) preference).getEntries()[index]; ((ListPreference) preference).setSummary(entry); return true; } });
static void updateListPreferenceSummaryToCurrentValue(final String prefKey, final PreferenceScreen screen) { // Because the "%s" summary trick of {@link ListPreference} doesn't work properly before // KitKat, we need to update the summary programmatically. final ListPreference listPreference = (ListPreference)screen.findPreference(prefKey); if (listPreference == null) { return; } final CharSequence entries[] = listPreference.getEntries(); final int entryIndex = listPreference.findIndexOfValue(listPreference.getValue()); listPreference.setSummary(entryIndex < 0 ? null : entries[entryIndex]); }