简体   繁体   中英

How to set an ID to an EpoxyModelWithHolder?

I am currently adding using Epoxy 3.9.0 (first time using it) and I'm creating an EpoxyModelWithHolder.

I'm setting an ID and I'm still getting: "You must set an id on a model before adding it."

ModelClass

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

Controller

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

data class Player(val image: Int = -1, val injured: Boolean, val name: String, val position: String)

Any ideas on how to fix this?

Simply remove var id : Long = 0 from PlayerModel class and rebuild,

( PlayerModel_ id(long id) function is automatically generated by Epoxy.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM