首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在安卓的OnClickListenrs环氧树脂模型中设置AirBNB (Kotlin)

如何在安卓的OnClickListenrs环氧树脂模型中设置AirBNB (Kotlin)
EN

Stack Overflow用户
提问于 2022-03-24 21:24:20
回答 1查看 122关注 0票数 0

因此,我使用的是AirBNB Epoxy (视图持有者版本),而且我似乎找不到可以在AirBNB Epoxy中设置onClickListeners的信息。任何信息都有帮助,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-04-05 05:15:49

根据环氧树脂文件

代码语言:javascript
复制
@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)
        }
    }
}

应该直接实例化生成的模型,并为每个属性设置一个setter:

代码语言:javascript
复制
ButtonModel_()
    .id(1)
    .text(R.string.my_text)
    .clickListener { view -> /* do something */ }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71609611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档