簡體   English   中英

為什么Epoxy不生成模型類?

[英]Why Epoxy does not generate model class?

我想將 Epoxy 用於帶有 kotlin 的 recyclerView,但 Epoxy Model 沒有生成 PostModel_() 類,它有什么問題?

@EpoxyModelClass(layout = R.layout.iteam)
abstract class PostModel : EpoxyModelWithHolder<PostModel.PostHolder>() {
  @EpoxyAttribute
  lateinit var userName: String
  @EpoxyAttribute
  lateinit var avatarIcon: Drawable
  @EpoxyAttribute
  lateinit var post: Drawable

  override fun bind(holder: PostHolder) {
    holder.avatarIcon.setImageDrawable(avatarIcon)
    holder.post.setImageDrawable(post)
    holder.name.text = userName

  }

  class PostHolder : BaseEpoxyHolder() {
    @BindView(R.id.name)
    lateinit var name: TextView
    @BindView(R.id.ic_avatar)
    lateinit var avatarIcon: ImageView
    @BindView(R.id.post)
    lateinit var post: ImageView
  }

}

在 Kotlin 中使用 Epoxy 時的一個常見錯誤是混合注釋處理引擎。 如果您從 Epoxy 的自述文件中復制此內容:

dependencies {
  implementation 'com.airbnb.android:epoxy:3.x.y'
  // Add the annotation processor if you are using Epoxy's annotations (recommended)
  annotationProcessor 'com.airbnb.android:epoxy-processor:3.x.y'
}

您可能忘記在同一自述文件中幾行后應用他們為 kotlin 用戶建議的內容:

確保使用kapt而不是annotationProcessor

我錯誤地從模型文件中刪除了第一行:

package com.myCustomDomain.myapp.epoxyModel

所以自動生成的文件是用錯誤的文件名生成的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM