


Private val name = itemView.findViewById(R.id.name) In this example, there is a sample model called ContentItem, so the click will return an item of that type: public interface OnItemClickListener In Java, you would need an interface that specifies listener’s behaviour. My mechanism consists of passing the listener as a parameter to the constructor and then assign it when I bind the data to the view in onBindViewHolder. There are many ways to achieve this, but I will show you the way I usually do it. Many people asked me how to do this, so that’s why I decided to write about it.

If you’ve used a RecyclerView, you may know that they don’t have a setOnItemClickListener as ListView had, so we have to create our own way to do it.
