In Android's data binding documentation, it says that
You can also write adapters for android namespace.
I followed the sample code in that documentation and tried to bind to TextView's android:text
setter.
This is the BinderAdapter I wrote:
@BindingAdapter("android:text")
public static void setText(TextView view, CharSequence text) {
view.setText(text + " - the BinderAdapter works!");
Log.d("MY_TAG", "the BinderAdapter works!");
}
and this is the layout:
<?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>
When I run the app I expect to see the text "This is dummy text - the BinderAdapter works!", however, the text I see is "This is dummy text". Moreover, looking at the logs I don't see the setText()
being called.
I read (here) suggestions for using a namespace other than "android", however, it is important to me that I will not need to pay special attention and place different namespaces throughout my app.
What am I doing wrong?