Most visited

Recently visited

InverseBindingMethod

public abstract @interface InverseBindingMethod
implements Annotation

android.databinding.InverseBindingMethod


InverseBindingMethod用于确定如何侦听对View属性的更改以及要调用的getter方法。 InverseBindingMethod应作为InverseBindingMethods一部分与任何类关联。

 @InverseBindingMethods({@InverseBindingMethod(
     type = android.widget.TextView.class,
     attribute = "android:text",
     event = "android:textAttrChanged",
     method = "getText")})
 public class MyTextViewBindingAdapters { ... }
 

method是可选的。 如果未提供,则使用属性名称查找方法名称,前缀为“is”或“get”。 为属性android:text ,数据绑定将搜索public CharSequence getText()上方法TextView

event是可选的。 如果未提供,则为事件名称分配后缀为AttrChanged的属性名称。 对于android:text属性,默认事件名称应为android:textAttrChanged 该事件应使用BindingAdapter进行设置。 例如:

 @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

Inherited methods

From interface java.lang.annotation.Annotation

Hooray!