我想在 epoxy.HotelItemModel_()
中创建自定义环氧树脂模型类 Epoxy Controller
中未生成类
@EpoxyModelClass(layout = R.layout.singlefood_layout)
abstract class HotelItemModel (@EpoxyAttribute var food: Food) : EpoxyModelWithHolder<HotelItemModel.FoodHolder>() {
override fun bind(holder: FoodHolder) {
holder.imageView.setImageResource(food.image)
holder.titleView.text = food.title
}
inner class FoodHolder : KotlinHolder() {
val imageView by bind<ImageView>(R.id.image)
val titleView by bind<TextView>(R.id.title)
val descView by bind<TextView>(R.id.desc)
}
}
最佳答案
尝试将构造函数留空并将 Food
对象作为可选字段
@EpoxyModelClass(layout = R.layout.singlefood_layout)
abstract class HotelItemModel() : EpoxyModelWithHolder<HotelItemModel.FoodHolder>() {
@JvmField
@EpoxyAttribute
var food: Food? = null
// ...
}
关于android - 为什么 Epoxy recyclerview 不在 kotlin 中生成自定义模型类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59280566/