@Retention(value=CLASS) @Target(value=METHOD) public @interface PreferenceChange
This annotation is intended to be used on methods to receive events defined
by
OnPreferenceChangeListener#onPreferenceChange(Preference, Object)
when the value of a Preference has been changed by the user and
is about to be set and/or persisted.
The annotation value should be one or several R.string.* fields that refers
to Preference or subclasses of
Preference or
android.support.v7.preference.Preference or subclasses of
android.support.v7.preference.Preference. If not set, the method
name will be used as the R.string.* field name. This annotation only can be
used inside EActivity or
EFragment annotated
class, which is a subclass of PreferenceActivity or PreferenceFragment(Compat), respectively.
The method MAY have multiple parameter:
Preference (or a subclass) or
android.support.v7.preference.Preference (or a subclass)
parameter to know which preference was targeted by this eventObject, String, Set of strings
and also a Boolean, Float, Integer, Long or
their corresponding primitive types to obtain the new value of the
Preference. Please note with number types, we assume that the
newValue parameter coming from the Preference is a
String, so we parse it to a number object (Android
Preference classes use Strings instead of number
objects).
Example :
@PreferenceChange(R.string.myPref)
void checkedChangedOnMyButton(boolean newValue, Preference preference) {
// Something Here
}
@PreferenceChange
void myPrefPreferenceChanged(Preference preference) {
// Something Here
}
@PreferenceChange
void myPrefPreferenceChanged(ListPreference preference) {
// Something Here
}
@PreferenceChange({R.string.myPref1, R.string.myPref2})
void preferenceChangeOnMultiplePrefs(Preference preference, String newValue) {
// Something Here
}
@PreferenceChange(R.string.myPref)
void preferenceChangeOnMyPref() {
// Something Here
}
PreferenceClickpublic abstract int[] value
public abstract String[] resName
Copyright © 2010–2018 simpligility technologies inc.. All rights reserved.