【问题标题】:Unable to find symbol FragmentBindingImpl with databinding bindingadapter android?无法使用数据绑定绑定适配器 android 找到符号 FragmentBindingImpl?
【发布时间】:2021-05-05 06:15:03
【问题描述】:

以下是我的主要布局,其中包含了另一个布局

<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="userName"
        type="String" />

    <variable
        name="hasEnded"
        type="Boolean" />

    <variable
        name="showLoader"
        type="Boolean" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/parent_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/base_chat_background">

    <com.commonui.AppBar
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@{userName}"
        app:addWindowInsetPaddingTop="@{true}"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:paddingTop="16dp"
        android:paddingBottom="70dp"
        app:addWindowInsetPaddingBottom="@{true}"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/app_bar" />

  

    <include
        android:id="@+id/feedbackLayout"
        visibleIf="@{hasEnded}"
        layout="@layout/chat_feedback"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <ProgressBar
        android:id="@+id/loader"
        visibleIf="@{showLoader}"
        android:layout_width="44dp"
        android:layout_height="44dp"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        android:indeterminate="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/app_bar" />

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

我有一个扩展函数,我用它来处理 XML 中视图的可见性

@BindingAdapter("visibleIf")
fun setVisibleIf(view: View, visible: Boolean) {
view.visibility = if(visible) View.VISIBLE else View.GONE
}

当我将 visibleIf="@{hasEnded}" 添加到包含的布局并构建项目时,我收到错误

error: cannot find symbol
import com.chat.databinding.FragmentPeerchatBindingImpl;

 symbol:   class FragmentChatBindingImpl
 location: package com.chat.databinding

可能是什么原因造成的?

【问题讨论】:

标签: android kotlin fragment android-databinding


【解决方案1】:

显然包含的布局暂时不支持绑定适配器

另一种方法是将您的变量从主布局发送到包含的布局

我们可以在这里使用app:showFeedback="@{hasEnded}" showFeedback 是包含布局中定义的绑定变量。 hasEnded 是主布局中定义的变量

【讨论】:

    猜你喜欢
    • 2019-07-19
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    相关资源
    最近更新 更多