Edit Text Preference Constraints

github: T06.10- EditTextPreferenceConstraints

* The below material is from Udacity Nanodegree Program- Become an Android Developer *

Setting an acceptable range

To limit the acceptable values between 0 (non inclusive) and 3 (inclusive) we opted to use a PreferenceChangeListener – this is not the same as a SharedPreferenceChangeListener. The differences are:

  • SharedPreferenceChangeListener is triggered after any value is saved to the SharedPreferences file.
  • PreferenceChangeListener is triggered before a value is saved to the SharedPreferences file. Because of this, it can prevent an invalid update to a preference. PreferenceChangeListeners are also attached to a single preference.

Continue reading