Code example for Preference.OnPreferenceChangeListener

Methods: onPreferenceChange

0
    preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override 
      public boolean onPreferenceChange(Preference pref, Object newValue) {
        updatePreferenceSummary(pref, options, values, summaryId, (String) newValue);
        if (listener != null) {
          listener.onPreferenceChange(pref, newValue);
        } 
        return true; 
      } 
    }); 
    updatePreferenceSummary(preference, options, values, summaryId, value);
    if (listener != null) {
      listener.onPreferenceChange(preference, value);
    } 
  } 
 
  /** 
   * Updates a preference when a stored value changes. 
   *  
   * @param preference the preference 
   * @param options the list of displayed options