我目前正在添加使用 Epoxy 3.9.0(第一次使用它)并且我正在创建一个 EpoxyModelWithHolder。
我正在设置一个 ID,但我仍然收到:“您必须先在模型上设置一个 ID,然后再添加它。”
模型类
abstract class PlayerModel: EpoxyModelWithHolder<PlayerModel.PlayerHolder>() {
@EpoxyAttribute
var id : Long = 0
@EpoxyAttribute
@DrawableRes
var image : Int = 0
@EpoxyAttribute
var injured : Boolean = false
@EpoxyAttribute
var name : String = ""
@EpoxyAttribute
var position : String = ""
// Busniess Logic
控制器
class PlayerController : EpoxyController() {
var playerItems : List<Player> = PlayerDataFactory.getPlayerItems()
override fun buildModels() {
var i : Long = 0
playerItems.forEach { player ->
PlayerModel_()
.id(i++)
.image(player.image)
.injured(player.injured)
.name(player.name)
.position(player.position)
.addTo(this)
}
}
}
数据类
data class Player(val image: Int = -1, val injured: Boolean, val name: String, val position: String)
有想法该怎么解决这个吗?