我正在尝试使用kotlin编写一个android wear应用程序,其中包含一系列项目。为了启用循环滚动,我使用WearableRecyclerView。但是遇到了这个错误未解决的引用:Adapter。相同的代码在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
}
}