android - 库项目中的 DataBinding BindingAdapter 未应用

标签 android android-databinding android-binding-adapter

我正在创建一个多模块项目。 我想在模块中共享 BindingAdapter。 但是,出现以下错误。

com.github.takahirom.bindingadapter_in_library.databinding
e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:customText' with parameter type java.lang.String on android.widget.TextView. file:/Users/takahirom/git/bindingadapterinlibrary/app/src/main/res/layout/content_main.xml loc:16:34 - 16:47 ****\ data binding error ****

    at android.databinding.tool.processing.Scope.assertNoError(Scope.java:112)
    at android.databinding.annotationprocessor.ProcessDataBinding.doProcess(ProcessDataBinding.java:109)
    at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:73)
    at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:99)

这是示例项目。 https://github.com/takahirom/databinding-in-library-sample

应用程序模块https://github.com/takahirom/databinding-in-library-sample/blob/master/app/src/main/res/layout/content_main.xml

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:customText="@{`Hello World!`}"

库模块https://github.com/takahirom/databinding-in-library-sample/blob/master/library/src/main/java/TestBinding.kt (如果我将此文件放在应用程序模块中,则不会发生错误)

@BindingAdapter("app:customText")
fun customText(textView: TextView, text: String) {
    textView.text = "** $text **"
}

最佳答案

用这个代替

@BindingAdapter("customText")

绑定(bind)适配器中不考虑 namespace

关于android - 库项目中的 DataBinding BindingAdapter 未应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53975575/

相关文章:

android - 在 Android Gallery App 中创建自定义相册

java - Android 应用程序中 Spring RestTemplate 的奇怪问题

android - 如何让xml中的 `onClick()`调用两个方法?

kotlin - 在使用 Android 数据绑定(bind)和 Kotlin 的自定义 BindingAdapter 中使用 lambda

java - 从 Web 服务检索数据后 Android 数据绑定(bind)不更新 UI

java - 如何创建一个可以将多个类作为输入的方法

Android TextView 对齐文本

Android 数据绑定(bind)微调器适配器

android - 如何在 DataBinding Android 的 BindingAdapter 方法中提供默认值

Android BindingAdapter 的执行顺序?