首页 > 解决方案 > Algolia 的 xml 的“属性”引发编译错误

问题描述

我正在尝试使用他们的结果 UI 并遵循他们的指南来实现 Algolia。

我已将我的应用程序的 build.gradle 放入dataBinding.enabled true如下

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.0"
    dataBinding.enabled true
    ......

在我的单次点击布局中,我只有一个 TextView,我尝试按照以下说明对其进行 binf,但它会引发编译错误:

<?xml version="1.0" encoding="utf-8"?>
<layout
        xmlns:algolia="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android">

    <androidx.constraintlayout.widget.ConstraintLayout
            xmlns:tools="http://schemas.android.com/tools"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <TextView
                android:id="@+id/algolia_question_title"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                tools:text="Not able to succefully rum npm install comand on git bash"
                android:fontFamily="@font/roboto_medium"
                android:textSize="15sp"
                android:textColor="@color/gray900"
                algolia:layout_constraintStart_toStartOf="parent"
                android:layout_marginStart="24dp"
                algolia:layout_constraintTop_toTopOf="parent"
                android:layout_marginTop="8dp"
                algolia:layout_constraintEnd_toEndOf="parent"
                android:layout_marginEnd="24dp"
                algolia:attribute='@{"title"}'/>
        <View
                android:id="@+id/divider4"
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="?android:attr/listDivider"
                algolia:layout_constraintTop_toBottomOf="@+id/algolia_question_title"
                android:layout_marginTop="8dp"/>

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

如果我删除这一行algolia:attribute='@{"title"}',它编译就好了。我哪里错了?

编辑:我能够找到一条错误消息,内容如下: Cannot find the setter for attribute 'algolia:attribute' with parameter type java.lang.String on android.widget.TextView.file:C\

该消息可能还有更多内容,但仅当我将鼠标悬停在某个错误行上并一直持续到屏幕末尾时才会出现,因此由于我不熟悉此消息,因此我无法判断是否还有更多内容。

标签: androidxmlalgolia

解决方案


添加此实现后添加了我的问题

implementation 'com.algolia:instantsearch-androidx:1.15.2'

推荐阅读