1

我成功地让环氧树脂从此生成代码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
    }
}

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

4

1 回答 1

0

在函数和类上使用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
    }
}
于 2018-06-30T01:10:03.423 回答