android - 未应用库项目中的 DataBinding BindingAdapter
问题描述
我正在创建一个多模块项目。我想在模块中共享 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
<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(如果我把这个文件放在app模块中,错误不会发生)
@BindingAdapter("app:customText")
fun customText(textView: TextView, text: String) {
textView.text = "** $text **"
}
解决方案
改用这个
@BindingAdapter("customText")
绑定适配器中不考虑名称空间
推荐阅读
- java - 类中的 main() 与接口中的 main()
- php - 未定义索引:级别
- django - 中级 Django 2.0 管理操作页面未显示
- csv - 在 NetLogo 中导入 CSV 文件
- python - 将 cookies txt 文件加载到 Python 中
- java - 为什么有人会在 java 1.8 的接口中定义静态方法?
- c# - linux 中单声道上的 iso-2022-jp 字符集(Amazon AMI)
- c# - 即使存在 C# selenium,也无法在页面上找到此元素
- assembly - memcmp 忽略奇数位置的字符
- amazon-web-services - 如何在 AWS VPC 的私有子网中设置实例?