android – Kotlin中未解决的引用WearableRecyclerView.Adapter错误

我正在尝试创建一个带有项目列表的android服装应用程序.为了启用循环滚动,我在kotlin中使用WearableRecyclerView编码.但是面对这个错误未解决的参考:适配器java中的相同代码不会抛出此错误!我还在kotlin中引用了内部和外部类的概念. Adapter类是RecyclerView的抽象类,它又由WearableRecyclerView扩展.任何指导都会有很大用处,谢谢!

这是我的代码

class CustomRecyclerAdapter(context: Context,dataSet: Array<String>): WearableRecyclerView.Adapter<CustomRecyclerAdapter.viewHolder>() {



var mDataSet: Array<String>
var mcontext: Context


init {
    mDataSet = dataSet
    mcontext=context
}

   inner class viewHolder(view: View) : WearableRecyclerView(mcontext) {

    val mTextView: TextView

    init {
        mTextView = view.findViewById(R.id.textView)
    }

    override fun toString(): String {
        return mTextView.text as String
    }
}

fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): viewHolder {
    val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.recycler_row_item, viewGroup, false)

    return viewHolder(view)
}

fun onBindViewHolder(viewHolder: viewHolder, position: Int) {
    // Replaces content of view with correct element from data set
    viewHolder.mTextView.text = mDataSet[position]
}

// Return the size of your dataset (invoked by the layout manager)
fun getItemCount(): Int {
    return mDataSet.size
}

}
最佳答案
你的类内部类viewHolder(view:View):WearableRecyclerView(mcontext)必须扩展WearableRecyclerView.ViewHolder而不是WearableRecyclerView,如:

inner class viewHolder(view: View) : WearableRecyclerView.ViewHolder(view)

转载注明原文:android – Kotlin中未解决的引用WearableRecyclerView.Adapter错误 - 代码日志