Wednesday , January 12 2022

Abstract RecyclerView Adapter to Eliminate Some Boiler-plate Code – Android Coding by DMTechnolab

Hi everyone, in this post we will learn how to make one Abstract RecyclerView Adapter. Abstraction is an object-oriented programming concept, and we all learn it in our books. But the irony is that most of us do not use its power. Even I did not pay much attention to these OOP design concepts in my previous tutorials. But now I think the practical use of these concepts should be taught to all.

We all create RecyclerView to display a list in our application. And you already know that to create RecyclerView we create a RecyclerViewAdapter. For each RecyclerView we create adapters and the same code occurs repeatedly in the adapter, but with the help of abstraction we can eliminate a lot of code to make our adapters narrower.

In this post I will use one of my previous tutorials, you can watch the video below.

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

Creating an abstract RecyclerView adapter

So we will create an abstract RecyclerView adapter and after creating it, we will use other RecyclerView adapters to the same adapter whenever needed. So what we are creating here will be used as the base class for all our RecyclerViewAdapters.

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

  • The normal operation, which we do in all our RecyclerViewAdapter, we will put inside this class. And then instead of using RecyclerView.Adcape we will use this class in our RecyclerViewAdapter classes.
  • You can see below; An example of using this class as a RecyclerViewAdapter class.
  • Now if you compare this adapter with your previous adapter, you can see how brief our class is.

Abstract Recycled Optimizer – Video Explanation

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

Abstract RecyclerView Adapter – Source Code

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

If you liked this post, then do share it with your friends, thank you

Belal Khan ProfileBelal Khan Profile

Hi, my name is Belal Khan and I am Google Developers Specialist (GDE) for Android. A passion for teaching made me this blog. If you are an Android developer, or you are learning about Android development, I can help you a lot with simplified coding.

Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *