Stay organized with collections
Save and categorize content based on your preferences.
InverseBindingListener
public
interface
InverseBindingListener
android.databinding.InverseBindingListener
|
A listener implemented by all two-way bindings to be notified when a triggering change happens.
For example, when there is a two-way binding for android:text, an implementation of
InverseBindingListener
will be generated in the layout's binding class.
private static class InverseListenerTextView implements InverseBindingListener {
@Override
public void onChange() {
mObj.setTextValue(mTextView.getText());
}
}
A BindingAdapter
should be used to assign the event listener.
For example, android:onTextChanged
will need to trigger the event listener
for the android:text
attribute.
@InverseBindingAdapter(attribute = "android:text", event = "android:textAttrChanged")
public static void captureTextValue(TextView view, ObservableField<CharSequence> value) {
CharSequence newValue = view.getText();
CharSequence oldValue = value.get();
if (oldValue == null) {
value.set(newValue);
} else if (!contentEquals(newValue, oldValue)) {
value.set(newValue);
}
}
@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);
}
Summary
Public methods |
abstract
void
|
onChange()
Notifies the data binding system that the attribute value has changed.
|
Public methods
onChange
void onChange ()
Notifies the data binding system that the attribute value has changed.
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.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# InverseBindingListener\n======================\n\n\n`\npublic\n\n\ninterface\nInverseBindingListener\n`\n\n\n`\n\n\n`\n\n|--------------------------------------------|\n| android.databinding.InverseBindingListener |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA listener implemented by all two-way bindings to be notified when a triggering change happens.\nFor example, when there is a two-way binding for android:text, an implementation of\n`InverseBindingListener` will be generated in the layout's binding class. \n\n```\n private static class InverseListenerTextView implements InverseBindingListener {\n @Override\n public void onChange() {\n mObj.setTextValue(mTextView.getText());\n }\n }\n \n```\n\n\nA [BindingAdapter](/reference/android/databinding/BindingAdapter) should be used to assign the event listener.\nFor example, `android:onTextChanged` will need to trigger the event listener\nfor the `android:text` attribute. \n\n```\n @InverseBindingAdapter(attribute = \"android:text\", event = \"android:textAttrChanged\")\n public static void captureTextValue(TextView view, ObservableField\u003cCharSequence\u003e value) {\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 @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\u003cbr /\u003e\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onChange](/reference/android/databinding/InverseBindingListener#onChange())`() ` Notifies the data binding system that the attribute value has changed. |\n\nPublic methods\n--------------\n\n### onChange\n\n```\nvoid onChange ()\n```\n\nNotifies the data binding system that the attribute value has changed.\n\n\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)"]]