我在尝试使用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
答案 0 :(得分:5)
Kotterknife的bindView
代表仅适用于Activity
,Dialog
,ViewGroup
,Fragment
,支持库Fragment
的子类,以及回收者视图的ViewHolder
。我猜您正在尝试将视图绑定为ListAdapter
的属性,但要使其工作,您必须拥有可以调用findViewById
的对象。
对于非RecyclerView ViewHolder
,您可以尝试
class ViewHolder(view: View) {
val textView: TextView = view.findViewById(R.id.name) as TextView
}