Search code examples
androidkotlinandroid-databinding

Android databinding error: cannot find symbol of my custom @BindingAdapter


I'm trying to add an app global custom @BindingAdapter. I created TextViewBinding.kt file, and put it to the separate package com.my.app.binding.TextViewBinding. When I compile the app, I get the error

error: cannot find symbol TextViewAdapterKt.setTypeface(this.titleTextView, viewedJavaLangStringNormalJavaLangStringBold);

If I put the adapter function into an Activity, there are no errors. But, because it's app global adapter, I don't want it to belong to any particular view. So, where I should place the adapter function to get rid of the error?

TextViewAdapter.kt

@BindingAdapter("typeface")
fun TextView.setTypeface(style: String) {
    when (style) {
        "bold" -> setTypeface(null, Typeface.BOLD)
        else -> setTypeface(null, Typeface.NORMAL)
    }
}

my_list_item.xml

...
    <TextView app:typeface='@{viewed ? "normal" : bold"}' ... />
...

Solution

  • Finally I found the error reason. I just forgot to add package declaration to the top of TextViewAdapter.kt file.