簡體   English   中英

EpoxyRecyclerview 中的更新項目(通知數據更改)

[英]Update item (Notify Datachange) in EpoxyRecyclerview

我使用 kotlin 中的數據綁定實現了環氧樹脂 controller。

我需要做的是在我單擊任何項目時更新文本並通知它,就像在普通適配器中所做的那樣。 我有一個項目,它做這樣的事情https://github.com/xorum-io/epoxy_partial_update.git

但在這個項目中,他們創建了 EpoxyModel 並使用了 function

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

我不想創建任何 Model object 因為我在我的項目中使用數據綁定。

當我嘗試更新任何項目並調用環氧樹脂控制器應用程序崩潰的 function requestModelBuild時。

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.

以上是我在崩潰后收到的消息。

任何人都可以請幫忙。

更新您的模型(數據類)並提交數據,這將更新您要更新的項目。

override fun buildModels() {

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM