【问题标题】:Epoxy, Kotlin: Using @ModelView generates nothing with no errors环氧树脂,Kotlin:使用 @ModelView 不会产生任何错误
【发布时间】:2018-06-30 01:10:03
【问题描述】:

我成功地让epoxy 从此EpoxyModelClass 生成代码

@EpoxyModelClass(layout = R.layout.card_sample)
abstract class PhotoModel : EpoxyModelWithHolder<PhotoModel.Holder>() {
    @EpoxyAttribute
    var title: String? = null

    override fun bind(holder: PhotoModel.Holder) {
        holder.header.text = title
    }

    class Holder : EpoxyHolder() {
        override fun bindView(itemView: View) {
            header = itemView.findViewById(R.id.header_label)
        }

        lateinit var header: TextView
    }
}

但不幸的是不是来自ModelView。它构建时没有错误,但没有围绕此生成环氧树脂类:

@ModelView
abstract class HeaderView : LinearLayout {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    )
    private var titleProp: CharSequence? = null
    @TextProp(defaultRes = R.string.app_name)
    fun setTitle(title: CharSequence) {
        titleProp = title
    }
}

为此尝试了许多变体以使其正确,但构建日志中没有有用的错误。

【问题讨论】:

    标签: kotlin epoxy epoxy-modelview


    【解决方案1】:

    在函数和类上使用open 而不是abstract 似乎可行。

    @ModelView(defaultLayout = R.layout.card_sample)
    open class HeaderView : RelativeLayout {
        constructor(context: Context) : super(context)
        constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
        constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
            context,
            attrs,
            defStyle
        )
    
        private var titleProp: CharSequence? = null
        @TextProp(defaultRes = R.string.app_name)
        open fun setTitle(string: CharSequence?) {
            titleProp = string
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2018-12-09
      • 1970-01-01
      相关资源
      最近更新 更多