出现“Android Kotlin RecyclerView Adapter的onCreateViewHolder未被调用”的问题可能是由以下原因导致:
val layoutManager = LinearLayoutManager(context)
recyclerView.layoutManager = layoutManager
val adapter = MyAdapter(dataList)
recyclerView.adapter = adapter
override fun getItemCount(): Int {
return dataList.size
}
class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
// ViewHolder的内容
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_layout, parent, false)
return MyViewHolder(itemView)
}
fun updateData(newDataList: List) {
dataList = newDataList
notifyDataSetChanged()
}
通过检查以上几个方面,可以解决“Android Kotlin RecyclerView Adapter的onCreateViewHolder未被调用”的问题。