Abstract RecyclerView Adapter to Eliminate Some Boiler-plate Code

Hi everyone, in this post we will learn about making an Abstract RecyclerView Adapter. Abstraction is an object oriented programming concept, and we all learn it in our books. But the irony is most of us don’t use the power of it.  Even I didn’t pay much attention to these OOP design concepts in my previous tutorials. But now I think that the practical use of these concepts should be taught to everyone.

We all make RecyclerView for displaying a list in our application. And you already know that for making a RecyclerView we create a RecyclerViewAdapter. For each RecyclerView we create Adapter and the adapter contains same code again and again, but with the help of abstraction we can eliminate a lot of code to make our adapter concise.

In this post I will be using one of my previous tutorials, you can see the video below.

And a request to you all, if you like my content, please subscribe to my YouTube channel. 

Building an Abstract RecyclerView Adapter

So we will build an abstract RecyclerView adapter and after building it, we will be using the same adapter to the other RecyclerView adapters, whenever required. So what we are making here will be used as a Base class for all our RecyclerViewAdapters.

In the existing project that you can see in the above video, we will create a class named BaseRecyclerViewAdapter.

  • The common operations, that we perform in all our RecyclerViewAdapter, we will put inside this class. And then instead of using the RecyclerView.Adapter we will use this class in our RecyclerViewAdapter classes.
  • You can see below; an example of using this class as an RecyclerViewAdapter class.

  • Now if you compare this adapter to your previous adapter, you can see how concise our class is.

Abstract RecyclerView Adapter – Video Explanation

You can check a complete step by step video explanation of the concept from below given video.

Abstract RecyclerView Adapter – Source Code

For more clarity you can get a working project code from the link given below.

git hub repository
Get the Source Code

If you liked this post, then please share it with your friends. Thank You

1 thought on “Abstract RecyclerView Adapter to Eliminate Some Boiler-plate Code”

  1. Hello Belal,
    I appreciate you share your knowledge with us. I have learnt a lot from you. But it is hard for me to adapt the codes from Kotlin to Java. Can you share your tutorials both Kotlin and Java?


Leave a Comment