@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
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
. If not set, the method name
will be used as the R.string.* field name.
The method MAY have multiple parameter:
Preference
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 String
s 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({R.string.myPref1, R.string.myPref2}) void preferenceChangeOnMultiplePrefs(Preference preference, String newValue) { // Something Here } @PreferenceChange(R.string.myPref) void preferenceChangeOnMyPref() { // Something Here }
PreferenceClick
public abstract String[] resName
Copyright © 2010-2015. All Rights Reserved.