Package androidx.databinding
Annotation Type InverseBindingAdapter
-
@Target({METHOD,ANNOTATION_TYPE}) public @interface InverseBindingAdapterInverseBindingAdapter is associated with a method used to retrieve the value for a View when setting values gathered from the View. This is similar toBindingAdapters:@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:textAttrChangedeven 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
BindingAdapterto 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
BindingAdapters, InverseBindingAdapter methods may also takeDataBindingComponentas the first parameter and may be an instance method with the instance retrieved from theDataBindingComponent.- See Also:
DataBindingUtil#setDefaultComponent(DataBindingComponent),InverseBindingMethod
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.StringattributeThe attribute that the value is to be retrieved for.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.StringeventThe event used to trigger changes.
-
-
-
-
event
java.lang.String event
The event used to trigger changes. This is used inBindingAdapters for the data binding system to set the event listener when two-way binding is used.- Default:
- ""
-
-