0

I want to update data items in the RecyclerView after API call. I have used ObservableArrayList. After api call, I have used notifyChange() in setter method. When I am passing the ObservableArrayList to the XML then I am getting error like this:

msg:Cannot find the setter for attribute 'bind:categories_list' with parameter type android.databinding.ObservableArrayList<T> on android.support.v7.widget.RecyclerView

XML is:

<?xml version="1.0" encoding="utf-8"?>
<layout>

    <data>

        <variable
            name="list"
            type="ObservableArrayList" />

        <import type="android.databinding.ObservableArrayList" />
    </data>

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:bind="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardBackgroundColor="@color/white">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                bind:categories_list="@{list}" />
        </android.support.v7.widget.CardView>
    </android.support.constraint.ConstraintLayout>
</layout>
Insane Developer
  • 1,014
  • 10
  • 19
  • Look at this post. I think it may help you too. https://stackoverflow.com/questions/34019978/android-data-binding-observable-list-to-recyclerviews-adapter – Franz Oct 26 '19 at 18:40

1 Answers1

1

You need to use the @BindingAdapter("categories_list") annotation where you are handling the list. Check this answer for more details

EDIT

Not sure if you followed the right approach. The syntax looks weird. Usually here:

<variable
    name="list"
    type="ObservableArrayList" />

goes a model class of your own, and importing it and using it with both declarations also look weird to me, did you try:

<variable
    name="list"
    type="android.databinding.ObservableArrayList" />

?

Chisko
  • 3,092
  • 6
  • 27
  • 45