Three Simple Steps to Handle RecyclerView Item Click with Kotlin

Xi Wei
Xi Wei
Nov 7 · 1 min read

Just the other day, I was trying to remember how to do item click in a RecyclerView. So I searched for it and expected a short-simple example that I can copy and paste. Surprisingly, none of the examples were very intuitive. I wanted something that would take less than three minutes. So, here I am again, writing this super short 3-step tutorial.

Suppose I want to display a list of the Person items.

data class Person(val name: String, val age: Int)

It has a name and age. I would like to display the names in the list and show the age after they are clicked.

Step 1. I want to just pass in the list of people and the click function to my RecyclerView Adapter like this:

Step 2. In my PersonsAdapter, I want to pass down the click function to each ViewHolder.

Step 3. At last, each ViewHolder will link the click function with the view item.

That’s it. Three simple steps. Checkout GitHub to see the entire project. I hope this saves you some time.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade