当前位置:   article > 正文

Kotlin自定义View在databinding中使用attr自定义属性编译报错问题_databing中加入kotlin自定义view编译报错

databing中加入kotlin自定义view编译报错

Kotlin自定义View在databinding中使用attr自定义属性编译报错问题

问题描述:

在自定义view 中给attr.xml中自定义属性(book_name)设置 databinding数据之后,编译报错
xxxxx/demo/DataBinderMapperImpl.java:9: 错误: 找不到符号
import xxxx.demo.databinding.ActivityMainBindingImpl;

<com.xxx.CusView
            android:id="@+id/cusView"
            android:background="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:book_name="@{datarepository.bookName}"
            />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

原因分析:

在一篇csdn博客中收到启发。kotlin 这边使用attr自定义的属性名引用databinding数据会报错。改成在该自定义view中使用set属性名方式然后引用该属性则不报错

参考https://blog.csdn.net/qq_43522147/article/details/108609491
和那篇博客中问题不同之处在于自定义view那篇是使用自定义布局, 我这里是自绘制的自定义view出的问问题,解决思路和方法是和那篇一样的改使用set属性方式


解决方案:

自定义控件: CusView{

//自定义属性名称
var booName: String? = “”

}

在xml中使用:
<com.xxx.CusView
app:bookName=“datarepository.bookName”/>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/319982
推荐阅读
相关标签
  

闽ICP备14008679号