#6 Android RecyclerView Tutorial – Creating Data Model

Hello and welcome back guys this time we will be taking look at Data Models in RecyclerView. Data Models are used to feed information to RecyclerView items and store changes at run-time. Best way understand is by using an example consider we want create online shop. Now there are many products in shop and we decided to show all products as list and we used RecyclerView  to show this list of products. Now a single product has many attributes like id, name, description, price etc. now to represent single product we will create new class as shown below

this class is called Data Model of product. Now we know what is Data Model but there are many products in shop so we will use collections like ArrayList to store all the products and feed RecyclerView. So let’s get started.

If you don’t have my previous completed project then it will be better to start from my first post of RecyclerView for your better understanding or you can download project completed up to previous post and this post below

1.Video Tutorial

2.Creating Data Model 

Now inside project create new class which will be our item data model. This class will represent data of single item in RecyclerView. Class should  look like as shown below.


2. Updating Adapter 

Now in our previous Adapter we did not populated information using Data Model so we need make changes in Adapter so  go to Adapter.java class. and it should look like as shown below


2.Adding some dump data

MainActivity from this activity we will feed data to our RecyclerView Adapter and Adapter will then add it in RecyclerView. MainAcivity.java class should look as shown below.


Now if you are not using images from which are online then it’s important to add Internet permission to Manifest. That’s all run application result will be as shown below.


#1 Android RecyclerView Tutorial – Introduction
#2 Android RecyclerView Tutorial – Creating Adapter
#3 Android RecyclerView Tutorial – Layout Managers
#4 Android RecyclerView Tutorial – Layout , Material Design , Decoration Part 1
#5 Android RecyclerView Tutorial – Layout , Material Design , Decoration Part 2
#6 Android RecyclerView Tutorial – Creating Data Model


Share this post

Hello there, My name is Amardeep founder of loopwiki.com. I have experience in many technologies like Android, Java, Php etc. In this variety of technologies, I love Android App Development. If you have any idea and you want me to develop for you then let’s have chat Email: [email protected]

One Comment

  • Golden Chimusinde

    Thank you very much for these tuts, I really appreciate them (After desperate searches for days you finally gave me a tutourial I was Looking for)

    Nevertheless, I have one tiny request for you,

    after adding the data from my string arrays, how can I add OnClickListeners to the RecyclerView Items to view in detail the content of the description as we have restricted the description to at least 2 lines during the lecture series.

    Thank you so much sir for your help, I am a Beginner Android Developer

Leave a Reply

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