Android resource linking failed in binding adapter data binding

Viewed 386

I want to set text using binding adapter.Here is the MyBindingAdapter.kt

@BindingAdapter("android:setTitle")
fun setTitle(textView : TextView,text: String){
        textView.text = text
}

in activity_table.xml I used setTitle like this

  <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_weight="1"
            android:gravity="center"
            android:setTitle="Hello word"/>

and I getting below error in compile time and I getting below error at compile time

3 Answers

First make sure you have to enclose you layout within the <layout> tag

<layout
xmlns:android="http://schemas.android.com/apk/res/android">
..... </layout>

and @BindingAdapter("android:setTitle") change as @BindingAdapter("title")

it should work.

Android studio will not consider @BindingAdapter("android:setTitle") while binding it, you need to write only @BindingAdapter("setTitle") to execute it perfectly, otherwise it will give that binding error while compile time.

You need to change from @BindingAdapter("android:setTitle") to @BindingAdapter("setTitle") in your MyBindingAdapter.kt.

Also you need to change in xml file from android:setTitle="Hello word" to setTitle="Hello word"

It should work now!

Related