1

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.

ahuja007
  • 281
  • 2
  • 14
  • I think using `TypedEpoxyController` is safer to use. – beigirad Apr 14 '21 at 05:33
  • @beigirad Thanksfor advise. I tried with Typed2EpoxyController but setData function is not refreshing data. – ahuja007 Apr 14 '21 at 11:14
  • `setData` has no issue. check your data manipulation way or binding values to view. You can place them in your question. – beigirad Apr 14 '21 at 19:51
  • It was done. Thanks for advise. There was crash because of null value in my response data. After fixing that all.was okay. But still after setting data item.was not being updated. Then I used bind function. My purpose is solved for now but I still need to find a way using which I wouldn't need to create EpodyModel, item update must be done only via binding – ahuja007 Apr 15 '21 at 00:40

1 Answers1

0

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)
    }
Jimale Abdi
  • 2,574
  • 5
  • 26
  • 33