0

So I'm using AirBNB Epoxy (the view holders version) and I can't seem to find the information where I can set onClickListeners in AirBNB Epoxy. Any information helps, Thanks.

OEThe11
  • 341
  • 2
  • 11

1 Answers1

2

According to epoxy's document:

@EpoxyModelClass(layout = R.layout.model_button)
abstract class ButtonModel : EpoxyModelWithHolder<ButtonModel.Holder>() {

    // Declare your model properties like this
    @EpoxyAttribute
    @StringRes
    var text = 0

    @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
    var clickListener: View.OnClickListener? = null

    override fun bind(holder: Holder) {
        // Implement this to bind the properties to the view
        holder.button.setText(text)
        holder.button.setOnClickListener(clickListener)
    }

    class Holder : EpoxyHolder() {
        lateinit var button: Button
        override fun bindView(itemView: View) {
            button = itemView.findViewById(R.id.button)
        }
    }
}

The generated model should be instantiated directly, and has a setter for each property:

ButtonModel_()
    .id(1)
    .text(R.string.my_text)
    .clickListener { view -> /* do something */ }
beigirad
  • 4,986
  • 2
  • 29
  • 52