I am implementing the RecylcerView.Adapter class in Kotlin. I get a compile-time error, see Comments in the following code.
// Compile time Error: 'public' function exposes its 'internal' return type ViewHolder
class DietListAdapter(context: Context, private val foodList: ArrayList<Food>) : RecyclerView.Adapter<DietListAdapter.ViewHolder>() {
private val inflater: LayoutInflater
private var onItemClick: Callback<Void, Int>? = null
init {
inflater = LayoutInflater.from(context)
}
// Compile time Error: 'public' function exposes its 'internal' return type ViewHolder
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DietListAdapter.ViewHolder {
val holder = ViewHolder(inflater.inflate(R.layout.layout_food_list_item, parent, false))
return holder
}
// Compile time Error: 'public' function exposes its 'internal' parameter type ViewHolder
override fun onBindViewHolder(holder: DietListAdapter.ViewHolder, position: Int) {
holder.textViewFoodName.text = foodList[position].foodName
holder.textViewFoodDesc.text = foodList[position].foodDesc
holder.itemView.setOnClickListener {
if (onItemClick != null)
onItemClick!!.callback(foodList[position].foodId)
}
}
...
...
internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var textViewFoodName: TextView
var textViewFoodDesc: TextView
init {
textViewFoodName = itemView.findViewById(R.id.textViewFoodName) as TextView
textViewFoodDesc = itemView.findViewById(R.id.textViewFoodDesc) as TextView
}
}
...
...
}
I checked it in the Kotlin documentation, there is no solution.
Has anyone else encountered this problem?
source
share