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 = 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 = 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; } });
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]); } } } }
@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; }
int index = m_updateList.findIndexOfValue(newValue); 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; } };
beerPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference pref, Object newValue) { final ListPreference listPref = (ListPreference) pref; final int idx = listPref.findIndexOfValue((String) newValue); //Depending upon idx execute return true; } });
public boolean onPreferenceChange(Preference preference, Object newValue) { ListPreference listPref = (ListPreference) preference; int index = listPref.findIndexOfValue((String) newValue); SharedPreferences.Editor editor = sp.edit(); editor.putInt("my_pref", index); editor.apply(); return true; }
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) { int index = ((ListPreference) preference).findIndexOfValue(newValue.toString()); String entry = (String) ((ListPreference) preference).getEntries()[index]; preference.setSummary(entry); 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; } });
@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; } });
@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]); }