Android RecyclerView using Volley and Glide Android tutorial | Techpakka

In this RecyclerView Volley Tutorial, I’m going to show you how to create RecyclerView and load images from the server using libraries Volley and Glide. We will be creating a simple Quotes application. In my previous tutorial, I have shown you how to create a simple RecyclerView with a custom divider if you have not seen that yet you can check here Android RecyclerView Tutorial, Custom divider, OnCLickListener.

We will learn to

  1. Create a POJO class
  2. Create Adapter class
  3. Adding RecyclerView to layout and initialise in java
  4. Get data from server using Volley
  5. Set adapter to RecyclerView
  6. Show images using Glide library

So let’s jump into the tutorial 🙂

Here is what the result we get when we call getquotes.php file which we will later add URL of this file in our MainActivity.java to parse and show the data in RecyclerView in android.

getquotes.php

here from the above code snippet, you can see that different symbols are used. Those are JSON Arrays and Objects. Symbol ” [ ” represents array and ” { ” represents objects. In our example, we are adding different quotes “Objects” containing the author name, image URL and the quotes string(Which is in key: value pair which we will discuss later). These objects are added to a single array.

I’m not going to show you the code behind this file because it is just a static file with static data there’s nothing you got to learn. But in future, I’ll be adding Tutorial on creating JSON data from a dynamically fetched data from a database or from any other source and parse this in android to show in different views like RecyclerView.

1.Creating a new project and adding resources

1. Open Android studio and click on File -> new -> new project. now a pop-up window appears, add necessary properties for your project and create an empty activity.

2. In the app level build.gradle add the RecyclerView library, Volley, Glide inside the dependencies tag.

3. In the styles.xml located inside res->values change Theme.AppCompat.Light.DarkActionBarto Theme.AppCompat.Light.NoActionBar for viewing RecyclerView without ActionBar.

4. In the layout file of MainActivity which is activity_main add the following code

5. Now create a layout file with name recycler_content under res->layout which we will use it to design the content inside RecyclerView. Add the following code.

2. Java code for RecyclerView Volley Tutorial

6. Now we need to create two classes Data class and Adapter class. and add the following code.

Data.java

Adapter.java

7. So we have created the java files and added the code inside, let’s move to the part of creating RecyclerView and adding data.

Add the following code to the MainActivity.java

Congrats!! You have successfully completed this RecyclerView Tutorial:). test this on the device by clicking on the run button. I hope you got a screen like this, if not don’t worry just let me know what the problem is in the comment box below.