You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Kay-Uwe Janssen edited this page Oct 9, 2016
·
8 revisions
Since AndroidAnnotations 3.3
@PreferenceScreen
The @PreferenceScreen annotation adds the preference layout to the component. This annotation only can be used on subclasses of PreferenceActivity or PreferenceFragment, and the annotated must have @EActivity or @EFragment according to the type.
The annotation value should be an XML resource id referencing the preference layout.
This annotation can be used to inject a Preference or Preference subclass object to the annotated field. This annotation only can be used in subclasses of PreferenceActivity or PreferenceFragment, and the annotated must have @EActivity or @EFragment according to the type.
The annotation value must be a string resource id, referencing the key of the preference.
The injected preferences will be first available in @AfterPreferences annotated methods.
@EActivitypublicclassSettingsActivityextendsPreferenceActivity {
@PreferenceByKey(R.string.myPref1)
voidsetOnePreference(PreferencemyPreference1){
// do something with myPreference1
}
voidsetMultiplePreferences(@PreferenceByKey(R.string.myPref1) PreferencemyPreference1, @PreferenceByKey(R.string.checkBoxPref) CheckBoxPreferencecheckBoxPref){
// do something with myPreference1 and checkBoxPref
}
}
@PreferenceChange
The @PreferenceChange annotation indicates that the annotated method will be called when the corresponding Preference is about to be changed, and will receive events defined by OnPreferenceChangeListener.onPreferenceChange.
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 parameters:
A Preference parameter to know which preference was targeted by this event
An Object, or Set of Strings, or String to obtain the new value of the Preference
Usage example:
@PreferenceChange(R.string.myPref)
voidcheckedChangedOnMyButton(booleannewValue, Preferencepreference) {
// Something Here
}
@PreferenceChangevoidmyPrefPreferenceChanged(Preferencepreference) {
// Something Here
}
@PreferenceChange({R.string.myPref1, R.string.myPref2})
voidpreferenceChangeOnMultiplePrefs(Preferencepreference, StringnewValue) {
// Something Here
}
@PreferenceChange(R.string.myPref)
voidpreferenceChangeOnMyPref() {
// Something Here
}
Since AndroidAnnotations 3.3.1
Float, Integer, Long and corresponding primitive types are now supported for the newValue parameter. Because Android Preference classes use Strings instead of Numbers, AndroidAnnotations automatically parses it and pass the Number object to the @PreferenceChange annotated method.
Usage example:
@PreferenceChange(R.string.myPref1)
voidpreferenceChangeIntParameter(Preferencepreference, intnewValue) {
// Something Here
}
Since AndroidAnnotations 4.0.0
As of AndroidAnnotations 4.0.0 any subclass of Preference can be passed to the methods (eg. ListPreference).
@PreferenceClick
The @PreferenceClick annotation indicates that the annotated method will be called when the corresponding Preference is clicked by the user, and will receive events defined by OnPreferenceClickListener#onPreferenceClick.
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 one parameter:
A Preference parameter to know which preference was clicked
Usage example:
@PreferenceClick(R.string.myPref)
voidclickOnMyPref() {
// Something Here
}
@PreferenceClickvoidmyPrefPreferenceClicked(Preferencepreference) {
// Something Here
}
Since AndroidAnnotations 4.0.0
As of AndroidAnnotations 4.0.0 any subclass of Preference can be passed to the methods (eg. ListPreference).
Methods annotated with @AfterPreferences will be called after addPreferenceFromResource is called by the generated classs.
This occurs AFTERaddPreferenceFromResource which is called at the end of super.onCreate(). Any preference depending code should be done in an @AfterPreferences annotated method.