Search code examples
androidkotlinfragmentandroid-databinding

Unable to find symbol FragmentBindingImpl with databinding bindingadapter android?


Below is my main layout where I have included another layout

<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>

I have an extension function with which I am handling the visibility of views in XML

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

When I add visibleIf="@{hasEnded}" to my included layout and build the project I get the error

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

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

What could be the cause of it?


Solution

  • Apparently included layout doesn't support binding adapter for now

    Alternative is to send your variable from main layout to included layout

    We can use app:showFeedback="@{hasEnded}" here showFeedback is the binding variable defined in included layout. hasEnded is the variable defined in the main layout