在Android的data binding documentation中,它说
您还可以为android命名空间编写适配器。
我按照该文档中的示例代码进行操作,并尝试绑定到TextView' android:text
setter。
这是我写的BinderAdapter:
@BindingAdapter("android:text")
public static void setText(TextView view, CharSequence text) {
view.setText(text + " - the BinderAdapter works!");
Log.d("MY_TAG", "the BinderAdapter works!");
}
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is dummy text"/>
</RelativeLayout>
当我运行应用程序时,我希望看到文本&#34;这是虚拟文本 - BinderAdapter正常工作!&#34;但是,我看到的文本是&#34;这是虚拟文本&#34; 。此外,查看日志我不会看到setText()
被调用。
我读了(here)关于使用&#34; android&#34;以外的命名空间的建议,但是,对我来说很重要的是我不需要特别注意并在我的位置放置不同的命名空间应用
我做错了什么?