第一次使用 Epoxy Library。得到以下错误
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但仍然是同样的错误。