我试图在我的android应用程序中实现数据绑定,但是我遇到了以下问题:
java.lang.ClassNotFoundException: Didn't find class "android.view.data"
我的布局文件如下所示:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.myapp.views.fragments.LocationSearchFragment">
<!-- data setup -->
<data>
<variable name="location"
type="com.myapp.models.Address" />
</data>
</LinearLayout>
</layout>
我build.gradle
用以下几行更新了文件:
dataBinding {
enabled = true
}
根据文档建议:https : //developer.android.com/topic/libraries/data-binding/index.html。我正在运行最新版本的Android Studio。
您需要将data
定义放在您的之外LinearLayout
:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- data setup -->
<data>
<variable name="location"
type="com.myapp.models.Address" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.myapp.views.fragments.LocationSearchFragment">
</LinearLayout>
</layout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句