In the last post, we discussed how to use GridViewLayout for recyclerview and you can read that post first, only because almost all the procedure is same, since we will be using the recyclerView here as well with Volley.
Lets Start By Creating Android Studio Project :
Once the project is synced, its time to create the required layout for our recycler view, We will create one custom layout view for the recyclerview. The layout contains ImageView for song cover image, Song title, and Artists image.
Also, Add RecyclerView widget in activity_main.xml files to display the data.
|Custom Layout For RecyclerView|
The XML layout source code is given below:
Now we will create the Song.java class, which will hold the data extracted from the JSON file. Let’s start by creating the class in our project, we will also create setter and getter for the fields we have in the class.
The Class source code is given below:
Now let’s create the adapter, that will help us bind the data to our custom layout using recyclerView.
The source code is given below:
The JSON data is saved in the URL given here:
Now the following code is used to extract the data from the given URL and We are using List<Song> to store each song object received from the JSON file. And afterward we are passing that to Adapter.
Final code of MainActivity.java is given below:
Finally, add Internet Permission at your AndroidManifest.xml file and we are ready to go.
>> Let’s Run the app and see what happens. Let’s go.
Watch Video Tutorials here:
FINAL FULL SOURCE CODE FOR THIS PROJECT IS GIVEN HERE .