Stay organized with collections
Save and categorize content based on your preferences.
InverseBindingAdapter
public
abstract
@interface
InverseBindingAdapter
implements
Annotation
android.databinding.InverseBindingAdapter
|
InverseBindingAdapter is associated with a method used to retrieve the value for a View
when setting values gathered from the View. This is similar to BindingAdapter
s:
@InverseBindingAdapter(attribute = "android:text", event = "android:textAttrChanged")
public static String captureTextValue(TextView view, CharSequence originalValue) {
CharSequence newValue = view.getText();
CharSequence oldValue = value.get();
if (oldValue == null) {
value.set(newValue);
} else if (!contentEquals(newValue, oldValue)) {
value.set(newValue);
}
}
The default value for event is the attribute name suffixed with "AttrChanged". In the
above example, the default value would have been android:textAttrChanged
even
if it wasn't provided.
The event attribute is used to notify the data binding system that the value has changed.
The developer will typically create a BindingAdapter
to assign the event. For example:
@BindingAdapter(value = {"android:beforeTextChanged", "android:onTextChanged",
"android:afterTextChanged", "android:textAttrChanged"},
requireAll = false)
public static void setTextWatcher(TextView view, final BeforeTextChanged before,
final OnTextChanged on, final AfterTextChanged after,
final InverseBindingListener textAttrChanged) {
TextWatcher newValue = new TextWatcher() {
...
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (on != null) {
on.onTextChanged(s, start, before, count);
}
if (textAttrChanged != null) {
textAttrChanged.onChange();
}
}
}
TextWatcher oldValue = ListenerUtil.trackListener(view, newValue, R.id.textWatcher);
if (oldValue != null) {
view.removeTextChangedListener(oldValue);
}
view.addTextChangedListener(newValue);
}
Like BindingAdapter
s, InverseBindingAdapter methods may also take
DataBindingComponent
as the first parameter and may be an instance method with the
instance retrieved from the DataBindingComponent
.
Summary
Public methods |
String
|
attribute()
The attribute that the value is to be retrieved for.
|
String
|
event()
The event used to trigger changes.
|
Public methods
attribute
String attribute ()
The attribute that the value is to be retrieved for.
event
String event ()
The event used to trigger changes. This is used in BindingAdapter
s for the
data binding system to set the event listener when two-way binding is used.
Annotations
Interfaces
Classes
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# InverseBindingAdapter\n\nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \\| [\\[Expand All\\]](#) \n\nInverseBindingAdapter\n=====================\n\n\n`\npublic\n\n\nabstract\n@interface\nInverseBindingAdapter\n`\n\n\n`\n\n\nimplements\n\n`[Annotation](http://developer.android.com/reference/java/lang/annotation/Annotation.html)`\n\n\n`\n\n|-------------------------------------------|\n| android.databinding.InverseBindingAdapter |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nInverseBindingAdapter is associated with a method used to retrieve the value for a View\nwhen setting values gathered from the View. This is similar to [BindingAdapter](/reference/android/databinding/BindingAdapter)s: \n\n```\n @InverseBindingAdapter(attribute = \"android:text\", event = \"android:textAttrChanged\")\n public static String captureTextValue(TextView view, CharSequence originalValue) {\n CharSequence newValue = view.getText();\n CharSequence oldValue = value.get();\n if (oldValue == null) {\n value.set(newValue);\n } else if (!contentEquals(newValue, oldValue)) {\n value.set(newValue);\n }\n }\n \n```\n\n\nThe default value for event is the attribute name suffixed with \"AttrChanged\". In the\nabove example, the default value would have been `android:textAttrChanged` even\nif it wasn't provided.\n\n\nThe event attribute is used to notify the data binding system that the value has changed.\nThe developer will typically create a [BindingAdapter](/reference/android/databinding/BindingAdapter) to assign the event. For example:\n\n\n```\n @BindingAdapter(value = {\"android:beforeTextChanged\", \"android:onTextChanged\",\n \"android:afterTextChanged\", \"android:textAttrChanged\"},\n requireAll = false)\n public static void setTextWatcher(TextView view, final BeforeTextChanged before,\n final OnTextChanged on, final AfterTextChanged after,\n final InverseBindingListener textAttrChanged) {\n TextWatcher newValue = new TextWatcher() {\n ...\n @Override\n public void onTextChanged(CharSequence s, int start, int before, int count) {\n if (on != null) {\n on.onTextChanged(s, start, before, count);\n }\n if (textAttrChanged != null) {\n textAttrChanged.onChange();\n }\n }\n }\n TextWatcher oldValue = ListenerUtil.trackListener(view, newValue, R.id.textWatcher);\n if (oldValue != null) {\n view.removeTextChangedListener(oldValue);\n }\n view.addTextChangedListener(newValue);\n }\n \n```\n\n\nLike `BindingAdapter`s, InverseBindingAdapter methods may also take\n[DataBindingComponent](/reference/android/databinding/DataBindingComponent) as the first parameter and may be an instance method with the\ninstance retrieved from the `DataBindingComponent`. \n**See also:**\n\n- [setDefaultComponent(DataBindingComponent)](/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent))\n- [InverseBindingMethod](/reference/android/databinding/InverseBindingMethod)\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|\n| ` `[String](http://developer.android.com/reference/java/lang/String.html) | ` `[attribute](/reference/android/databinding/InverseBindingAdapter#attribute())`() ` The attribute that the value is to be retrieved for. |\n| ` `[String](http://developer.android.com/reference/java/lang/String.html) | ` `[event](/reference/android/databinding/InverseBindingAdapter#event())`() ` The event used to trigger changes. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From interface ` `[java.lang.annotation.Annotation](http://developer.android.com/reference/java/lang/annotation/Annotation.html)` ` |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| | ` abstract `[Class](http://developer.android.com/reference/java/lang/Class.html)`\u003c? extends `[Annotation](http://developer.android.com/reference/java/lang/annotation/Annotation.html)`\u003e` | ` annotationType() ` | | ` abstract boolean` | ` equals(`[Object](http://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` abstract int` | ` hashCode() ` | | ` abstract `[String](http://developer.android.com/reference/java/lang/String.html) | ` toString() ` | ||\n\nPublic methods\n--------------\n\n### attribute\n\n```\nString attribute ()\n```\n\nThe attribute that the value is to be retrieved for.\n\n\u003cbr /\u003e\n\n| Returns ||\n|------------------------------------------------------------------------|--------|\n| [String](http://developer.android.com/reference/java/lang/String.html) | \u003cbr /\u003e |\n\n### event\n\n```\nString event ()\n```\n\nThe event used to trigger changes. This is used in [BindingAdapter](/reference/android/databinding/BindingAdapter)s for the\ndata binding system to set the event listener when two-way binding is used.\n\n\u003cbr /\u003e\n\n| Returns ||\n|------------------------------------------------------------------------|--------|\n| [String](http://developer.android.com/reference/java/lang/String.html) | \u003cbr /\u003e |\n\n-\n\n Annotations\n -----------\n\n - [Bindable](/reference/android/databinding/Bindable)\n - [BindingAdapter](/reference/android/databinding/BindingAdapter)\n - [BindingConversion](/reference/android/databinding/BindingConversion)\n - [BindingMethod](/reference/android/databinding/BindingMethod)\n - [BindingMethods](/reference/android/databinding/BindingMethods)\n - [InverseBindingAdapter](/reference/android/databinding/InverseBindingAdapter)\n - [InverseBindingMethod](/reference/android/databinding/InverseBindingMethod)\n - [InverseBindingMethods](/reference/android/databinding/InverseBindingMethods)\n - [InverseMethod](/reference/android/databinding/InverseMethod)\n-\n\n Interfaces\n ----------\n\n - [DataBindingComponent](/reference/android/databinding/DataBindingComponent)\n - [InverseBindingListener](/reference/android/databinding/InverseBindingListener)\n - [Observable](/reference/android/databinding/Observable)\n - [ObservableList](/reference/android/databinding/ObservableList)\n - [ObservableMap](/reference/android/databinding/ObservableMap)\n-\n\n Classes\n -------\n\n - [BaseObservable](/reference/android/databinding/BaseObservable)\n - [CallbackRegistry](/reference/android/databinding/CallbackRegistry)\n - [CallbackRegistry.NotifierCallback](/reference/android/databinding/CallbackRegistry.NotifierCallback)\n - [DataBindingUtil](/reference/android/databinding/DataBindingUtil)\n - [ListChangeRegistry](/reference/android/databinding/ListChangeRegistry)\n - [MapChangeRegistry](/reference/android/databinding/MapChangeRegistry)\n - [MergedDataBinderMapper](/reference/android/databinding/MergedDataBinderMapper)\n - [Observable.OnPropertyChangedCallback](/reference/android/databinding/Observable.OnPropertyChangedCallback)\n - [ObservableArrayList](/reference/android/databinding/ObservableArrayList)\n - [ObservableArrayMap](/reference/android/databinding/ObservableArrayMap)\n - [ObservableBoolean](/reference/android/databinding/ObservableBoolean)\n - [ObservableByte](/reference/android/databinding/ObservableByte)\n - [ObservableChar](/reference/android/databinding/ObservableChar)\n - [ObservableDouble](/reference/android/databinding/ObservableDouble)\n - [ObservableField](/reference/android/databinding/ObservableField)\n - [ObservableFloat](/reference/android/databinding/ObservableFloat)\n - [ObservableInt](/reference/android/databinding/ObservableInt)\n - [ObservableList.OnListChangedCallback](/reference/android/databinding/ObservableList.OnListChangedCallback)\n - [ObservableLong](/reference/android/databinding/ObservableLong)\n - [ObservableMap.OnMapChangedCallback](/reference/android/databinding/ObservableMap.OnMapChangedCallback)\n - [ObservableParcelable](/reference/android/databinding/ObservableParcelable)\n - [ObservableShort](/reference/android/databinding/ObservableShort)\n - [OnRebindCallback](/reference/android/databinding/OnRebindCallback)\n - [PropertyChangeRegistry](/reference/android/databinding/PropertyChangeRegistry)\n - [ViewDataBinding](/reference/android/databinding/ViewDataBinding)\n - [ViewStubProxy](/reference/android/databinding/ViewStubProxy)"]]