How to Create a COVID-19 Tracker Android App to See Details of any City and State in India?
In the previous article, we have discussed How to create a COVID-19 Tracker Android App which shows only the Global Stats. In this article, we will learn how to create a COVID-19 Tracker Android App which will show the details of any city in any State in India. Details like – Total Active cases, Cured Cases, Deaths, and the total number of confirmed cases of any respective city. Here in this App, let’s track demo of 5 cities and one can change according to his/her needs.
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: Now Add Some Files Before writing the XML and Java Code
- Go to app -> res -> values -> colors.xml section and set the colors for the app.
- These Colors are Used In the apps In various Places.
- Go to Gradle Scripts -> build.gradle (Module: app) section and import the following dependencies and click the “Sync Now” button to Sync the APP.
- To Learn More About Volley Library Click Here.
- Now Go to the app -> manifests -> AndroidManifests.xml section and allow “Internet Permission” because this App will use Internet Permission.
Step 3: Use JSON Parsing to fetch data from the website
- Click on this URL- https://api.covid19india.org/state_district_wise.json
- It will Show Data of the whole Country and in this, We Are Going to fetch data from here Only.
Step 4: Design the Layout of the activity_main.xml
- Go to app -> res -> layout -> activity_main.xml
- Add A TextView To the layout: To display GEEKSFORGEEKS at the top of the screen.
- Add A ListView To the Layout: To display the list of cities tracking details on the screen.
Step 5: Design the Layout for The ListView
- Create A new Layout by right click on the layout folder inside res Folder
- Then Click Layout Resource File and Set the name testing.xml
- Click Finish To save
- Click testing.xml and Start Design UI Layout for the ListView
- The Drawable file used in testing.xml is “arrow upward“. Go to drawable -> New -> Vector Asset and search for “arrow upward” and add it to your file.
Step 6: Create a New JAVA Class to fetch the data we want to fetch from the Website
- Create a new JAVA class name it as Model.java
- Use getters and setters functions to create a function for the data you want to fetch from the website.
Step 7: Create an Adapter Class
Now create a new JAVA Adapter Class to put the data that have fetched into a ListView that has created before.
Step 8: Working with MainActivity.java file
In this file, we are going to use the Volley library. Refer to the comments inside the code to understand the code.