
If we look at our adapter code now, you would see that it’s starting to do too much.

inner class MyViewHolder( itemView: View, private val onTextViewTextClicked: (position: Int) -> Unit ) : RecyclerView.ViewHolder(itemView) For the logic to pull the data out from the position, we will offload it onto the adapter. Instead of returning the whole data class back onto the callback, we will return only the position of ViewHolder. Currently, we're setting a new listener every single time, What if we could transfer it inside ViewHolder initialization or onto onCreateView, then it will only be executed one time and will be recycled for later use.


Notice anything that we could recycle here as well? The answer is the OnClickListener that is being used.
