1

我想在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)
    }
}  
4

1 回答 1

0

尝试将构造函数留空并将Food对象作为可选字段

@EpoxyModelClass(layout = R.layout.singlefood_layout)
    abstract class HotelItemModel() : EpoxyModelWithHolder<HotelItemModel.FoodHolder>() {

    @JvmField
    @EpoxyAttribute 
    var food: Food? = null
  // ...
  }
于 2019-12-25T06:48:23.880 回答