我正在尝试测试数据绑定,如此处所示的指南。我已经将以下内容包含在我的build.gradle文件(模块app)中:
compileSdkVersion 'android-MNC'
buildToolsVersion '23.0.0 rc2'
在项目 build.gradle 文件中,我已经将以下内容包含在我的依赖项中:
classpath "com.android.tools.build:gradle:1.3.0-beta2"
classpath "com.android.databinding:dataBinder:1.0-rc0"
布局文件与指南中给出的文件完全相同。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.firstName}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.lastName}"/>
</LinearLayout>
</layout>
最初出现了错误元素布局没有所需的属性layout_width和layout_height
。
我尝试通过分别分配match_parent来修复它。然后我在分配layout_height
和layout_width
到线性布局的行上得到了Error parsing XML: duplicate attribute
错误。
然后我尝试通过删除这些属性来修复问题。现在每次尝试编译时,都会看到这个错误-error: package my.package.name.databinding
不存在。
代码补全在我尝试使用此布局的碎片中完美工作。
那么我错过了什么?
user
POJO 类和Activity
类? - N Jmy.package.User
还是com.example.User
。 - J.G.Sebring