If you are looking for building a book library app and you want to load a huge data of books then for adding this feature, you have to use a simple API which is provided by Google, and of course, it’s free. In this article, we will take a look at the implementation of this API in our Android App.
What we are going to build in this article?
We will be building a simple application in which we will be searching different types of books and we will get to see the list of books related to that topic in our RecyclerView. For searching these books we will be using a free API provided by Google which holds a huge collection of books. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Add the dependency for Volley in your Gradle files
Navigate to the app > Gradle Scripts > build.gradle file and add below dependency in the dependencies section.
After adding the below dependencies in your gradle file now sync your project and now we will move towards our activity_main.xml file. As we will be using volley to fetch data from our API and Picasso image loading library to load images from URL.
Step 3: Adding permissions for the Internet
Navigate to the app > AndroidManifest.xml and add the below permissions to it.
As we will be loading the books from API so we have to request Internet permissions from the user. For that add the permissions for the internet in AndroidManifest.xml.
Step 4: Working with the activity_main.xml file
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
Step 5: Creating a Modal Class for storing our data from the API.
For creating a new Modal class. Navigate to the app > java > your app’s package name > Right-click on it and Click on New > Java class and give a name to our java class as BookInfo and add below code to it. Comments are added in the code to get to know in more detail.
Step 6: Create a new layout resource file
Go to the app > res > layout > right-click > New > Layout Resource File and name the file as book_rv_item and add the following code to this file.
Step 7: Creating an Adapter class for setting our data to the item of RecyclerView
Navigate to the app > java > your app’s package name > Right-click on it Click on New > Java class and name it as BookAdapter and add below code to it. Comments are added in the code to get to know in more detail.
Step 8: Creating a new Activity for displaying our Book Info in detail
Navigate to the app > java > your app’s package name > Right-click on it and click on New > Activity > Select Empty Activity and name it as BookDetails. Make sure to select Empty Activity.
Working with the activity_book_details.xml file:
Go to the activity_book_details.xml file and refer to the following code. Below is the code for the activity_book_details.xml file.
Working with the BookDetails.java file:
Go to the BookDetails.java file and refer to the following code. Below is the code for the BookDetails.java file. Comments are added inside the code to understand the code in more detail.
Step 9: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Check out the project on the below link: https://github.com/ChaitanyaMunje/LibraryApp