我是RecyclerView的新手,我想实现这一点,但是问题是我无法解析以下代码中的Viewholder引用,请帮帮我
class ViewAdapter : RecyclerView.Adapter(){ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewAdapter.ViewHolder { // return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.slider, parent, false)) // } } override fun getItemCount(): Int { TODO("not implemented") } override fun onBindViewHolder(holder: ViewAdapter.ViewHolder, position: Int) { TODO("not implemented") } }
您需要在班级ViewHolder
内部创建一个ViewAdapter
班级
样本代码
class ViewAdapter : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewAdapter.ViewHolder { // return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.slider, parent, false)) // } } override fun getItemCount(): Int { TODO("not implemented") } override fun onBindViewHolder(holder: ViewAdapter.ViewHolder, position: Int) { TODO("not implemented") } class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { } }