Android RecyclerView CLick Listener Tutorial

In Our Previous tutorial “Android RecyclerView Tutorial” . We had learned how to render a simple RecyclerView with a custom layout. We had also learn writing a adapter class and binding data the list of books displaying the title and author .

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 . There are many ways to achieve this, but I will show you the way I usually do it .

Let’s Get it Working

In this tutorial we are going to learn how to add recycler view item click listener. I assume that you have learned how to render a simple RecyclerView with a custom layout from my previous post “Android RecyclerView Tutorial” .

Step 1 ) Writing the click interface

Create an interface named and add below code. Here we declare two methods onClick and onLongClick to identify item click and long click respectively.

Step 2 ) Writing the Item Touch Class

Create a class named and add below code . Here we write the logic to detect click and long press on recycler view item .

Step 3 ) Defining click listener

Open and update the below changes. Here onClick() method will detect click on item and onLongClick will detect long click on item.

Run your app , click and long press the recycler view item .


Enjoy Coding and Share Knowledge