Android数据绑定类没有创建

时间:2018-04-05 13:52:26

标签: android data-binding android-databinding

对于我的Android应用程序,我正在使用数据绑定,它表现良好。当我在ImageView和按钮上添加一些Onclick代码时,它开始给出问题。这是我的代码。

activity_main.xml中

SELECT size(myStr) FROM myTable WHERE ...

item_category.xml

<data>

    <variable
        name="isLoading"
        type="boolean" />

    <import type="android.view.View" />

    <variable
        name="hasCategory"
        type="boolean" />

    <variable
        name="categoryViewModel"
        type="com.test.viewmodel.CategoriesViewModel" />
</data>

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.MainActivity">

    ..................................
..................................

    <Button
        android:id="@+id/deleteButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        android:textSize="10sp"
        android:onClick="@{() -> categoryViewModel.deleteAllCategory()}"
        android:text="DELETE ALL"
        app:layout_constraintEnd_toStartOf="@+id/searchButton"
        app:layout_constraintTop_toBottomOf="@+id/editText3" />
</android.support.constraint.ConstraintLayout>

这些只是改变已完成的两个视图。这是错误:

编译失败;有关详细信息,请参阅编译器错误输出。

引起:org.gradle.api.internal.tasks.compile.CompilationFailedException:编译失败;请参阅编译器错误输出以获取详细信     在org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:50)     在org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:35)     在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:98)     在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:51)     在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:37)     在org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)     在org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)     在org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:207)     在org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:192)     在org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:124)     在com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:125)

如果有人帮我找到错误,将会很有帮助。

1 个答案:

答案 0 :(得分:0)

您尝试移动xmlns。

<layout     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

<data>
    <variable
        name="category"
        type="com.test.db.entity.Category" />

    <variable
        name="categoryClickCallback"
        type="com.test.ui.CategoryAdapter.CategoryClickCallback" />
</data>

<android.support.constraint.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    ...........................................
..................................................


    <ImageView
        android:id="@+id/deleteImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:onClick="@{() ->  categoryClickCallback.onClickDelete(category)}"
        app:srcCompat="@mipmap/icon_delete" />

    ............................................
...........................................

</android.support.constraint.ConstraintLayout>
</layout>