我成功地让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
}
}
对此进行了许多尝试以使其正确,但是构建日志中没有任何有用的错误。
答案 0 :(得分: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
}
}