我正在试用新的数据绑定(bind)库。我有一个奇怪的问题,绑定(bind) visibility
属性没有编译。
这是xml文件的简化版:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="header"
type="com.example.EmailHeader" />
</data>
<RelativeLayout ... >
<TextView
...
android:text="@{header.senderName ?? header.senderAddress}"
android:visibility="@{header.hasAttachment ? View.VISIBLE : View.INVISIBLE}" />
</RelativeLayout>
</layout>
编译时收到以下消息:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Identifiers must have user defined types from the XML file. View is missing it
当我删除 android:visiblity
声明时,一切都会编译(并且可以工作!)。
我没有看到我在这里缺少什么
最佳答案
你还需要在data标签里面添加:
<import type="android.view.View" />
关于android - 数据绑定(bind)表达式未编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32068675/