首次使用Epoxy库。波纹管误差
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.以下是控制器代码:
class MyMatchesController : EpoxyController() {
override fun buildModels() {
for (i in 0 until 10) {
fillBestMatchesNotification {
id(i)
bestMatchesCount("100")
}
}
}
}这是模型代码
@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,但仍然存在相同的错误。
发布于 2021-03-23 15:58:39
id是一个保留属性,不能将其声明为带有@EpoxyAttribute的新字段。
只需定义所需的属性即可。id设置程序(具有不同的重载)将自动生成。
所以移除下面的几行。一切都会顺利的。
@EpoxyAttribute
var id: Long = 0https://stackoverflow.com/questions/66366904
复制相似问题