Android のデータ バインディング ドキュメントでは、次のように述べています。
Android 名前空間のアダプターを作成することもできます。
android:text
そのドキュメントのサンプル コードに従い、TextView のセッターにバインドしようとしました。
これは私が書いた 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>
アプリを実行すると、「これはダミー テキストです - BinderAdapter は動作します!」というテキストが表示されるはずですが、表示されるテキストは「これはダミー テキストです」です。setText()
さらに、ログを見ると、呼び出されていることがわかりません。
「Android」以外の名前空間を使用するための提案(ここ)を読みましたが、特別な注意を払ってアプリ全体に異なる名前空間を配置する必要がないことが重要です。
私は何を間違っていますか?