Update item (Notify Datachange) in EpoxyRecyclerview

2.5k Views Asked by At

I have epoxy controller implemented using databinding in kotlin.

What I need to do is update text when I click on any item and notify that as done in normal adapter. I got a project which does something like this https://github.com/xorum-io/epoxy_partial_update.git

But in this project they have created EpoxyModel and used function

override fun bind(view: View, previouslyBoundModel: EpoxyModel<*>) {
    super.bind(view, previouslyBoundModel)
}

I don't want to create any Model object as I am using databinding in my project.

When I try to update any item and call function requestModelBuild of epoxycontroller application crashes.

com.airbnb.epoxy.ImmutableModelException: The model was changed between being bound and when models were rebuilt

Epoxy attribute fields on a model cannot be changed once the model is added to a controller. Check that these fields are not updated, or that the assigned objects are not mutated, outside of the buildModels method. The only exception is if the change is made inside an Interceptor callback. Consider using an interceptor if you need to change a model after it is added to the controller and before it is set on the adapter. If the model is already set on the adapter then you must call `requestModelBuild` instead to recreate all models.

Above is message that I get after crash.

Can anyone please help.

1

There are 1 best solutions below

0
On

Update your Model(Data class) and submit data, this will update the item that you want to update.

override fun buildModels() {

        UserModel_()
            .id(user.id)
            .name(user.name)
            .onClickListener { model, parentView, clickedView, position ->
                user.name = "New updated name"
                setData(user)
            }
            .addTo(this)
    }