KotterKnife – 对某些类不能使用bindView(R.id.example_id)

尝试使用KotterKnife时出现以下错误 – 但只适用于某些类。 这是怎么回事?

e: /Users/user/dev/git/to14/android/src/main/kotlin/com.example/adapters/ChapterListAdapter.kt: (59, 34): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public fun <T : android.view.View> android.app.Dialog.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife public fun <T : android.view.View> android.support.v4.app.Fragment.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife public fun <T : android.view.View> android.app.Fragment.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife public fun <T : android.view.View> android.view.ViewGroup.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife public fun <T : android.view.View> android.support.v7.widget.RecyclerView.ViewHolder.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife public fun <T : android.view.View> android.app.Activity.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife 

Kotterknife的bindView委托只能用于ActivityDialogViewGroupFragment ,支持库Fragment和回收者视图的ViewHolder 。 我想你试图将视图作为ListAdapter属性来绑定,但为了让它工作,你必须有对象,你可以调用findViewById

对于非RecyclerView ViewHolder您可以尝试

 class ViewHolder(view: View) { val textView: TextView = view.findViewById(R.id.name) as TextView }