Code example for ListPreference

Methods: findIndexOfValuegetEntriessetSummary

0
	public boolean onPreferenceChange(Preference preference, Object newValue) {
		//如果是弹出列表在ListPreference中查找选中的是哪个元素. 
		if (preference instanceof ListPreference) {
			ListPreference listPreference = (ListPreference) preference;
 
			CharSequence[] entries = listPreference.getEntries();
			int index = listPreference.findIndexOfValue((String) newValue);
 
			listPreference.setSummary(entries[index]);
		//如果是seekbar在SeekBarPreference中查找选中的是哪个元素. 
		} else if (preference instanceof SeekBarPreference) {
			SeekBarPreference seekBarPreference = (SeekBarPreference) preference;
 
			seekBarPreference.setSummary(newValue.toString());
		} 
		return true; 
	} 
}