首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >com.airbnb.epoxy.IllegalEpoxyUsage:在添加id之前,必须在模型上设置一个id

com.airbnb.epoxy.IllegalEpoxyUsage:在添加id之前,必须在模型上设置一个id
EN

Stack Overflow用户
提问于 2021-02-25 10:38:46
回答 1查看 904关注 0票数 0

首次使用Epoxy库。波纹管误差

代码语言:javascript
复制
rocess: in.droom, PID: 25269
com.airbnb.epoxy.IllegalEpoxyUsage: You must set an id on a model before adding it. Use the @AutoModel annotation if you want an id to be automatically generated for you.

以下是控制器代码:

代码语言:javascript
复制
   class MyMatchesController : EpoxyController() {
    override fun buildModels() {
        for (i in 0 until 10) {
            fillBestMatchesNotification {
                id(i)
                bestMatchesCount("100")
            }
        }
    }
}

这是模型代码

代码语言:javascript
复制
    @EpoxyModelClass(layout = R.layout.fill_best_match_notification_layout)
abstract class FillBestMatchesFormNotificationModel : EpoxyModelWithHolder<FillBestMatchesFormNotificationModel.ViewHolder>() {

    @EpoxyAttribute
    var id: Long = 0

    @EpoxyAttribute
    var bestMatchesCount = ""


    override fun getDefaultLayout() = R.layout.fill_best_matches_notification_layout

    @CallSuper
    override fun bind(holder: ViewHolder) {
        super.bind(holder)
        holder.countTV.text = bestMatchesCount
    }

    override fun createNewHolder(): ViewHolder {
        return ViewHolder()
    }

    inner class ViewHolder : EpoxyHolder() {
        lateinit var countTV: TextView
        override fun bindView(itemView: View) {
            countTV = itemView.findViewById(R.id.matchedCountNotificationTV)
        }

    }
}

我试图从Model类中删除id,但仍然存在相同的错误。

EN

回答 1

Stack Overflow用户

发布于 2021-03-23 15:58:39

id是一个保留属性,不能将其声明为带有@EpoxyAttribute的新字段。

只需定义所需的属性即可。id设置程序(具有不同的重载)将自动生成。

所以移除下面的几行。一切都会顺利的。

代码语言:javascript
复制
@EpoxyAttribute
var id: Long = 0
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66366904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档