How to Build a Cryptocurrency Tracker Android App?
CryptoCurrency nowadays is in most demand and many people are investing in these currencies to get high returns. Many websites and applications provide us information about the rates of different cryptocurrencies available in the Crypto Market. In this article, we will be building a similar application in which we will be displaying the rates of different cryptocurrencies inside our application in RecyclerView.
What We Will be Building in this Application?
We will be building a simple application in which we will be displaying the rates of different cryptocurrencies inside our app’s RecyclerView. Below is the video in which we will get to see what we are going to build 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: Before going to the coding section first you have to do some pre-task
Go to app > res > values > colors.xml section and set the colors for your app.
Step 3: Adding dependency for Volley in build.gradle file
Go to Gradle Scripts > build.gradle (Module: app) section and import the following dependencies and click the “Sync Now” on the above pop-up.
// Volley library implementation 'com.android.volley:volley:1.1.1'
Step 4: Adding Internet Permissions in the AndroidManifest.xml file
Navigate to the app > AndroidManifest.xml file and add the below line of code in it.
Step 5: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Step 6: Creating a new Java file for storing our data
We have to store the data in a modal class for that we will be creating a new Java class file. For creating this file. Navigate to the app > java > your app’s package name > Right-click on it > New > Java Class option and then choose Class and name your file as CurrencyModal and add below code to it. Comments are added in the code to get to know in more detail.
Step 7: Creating a new layout file for our item of RecyclerView
Navigate to the app > res > layout > Right-click on it > New > Layout file and name it as currency_rv_item and add below code to it. Comments are added in the code to get to know in more detail. The below layout file be used to display each item of our RecyclerView.
Step 8: Creating a new Java class file for our Adapter class
Now for setting data to each item of our Recycler View. We have to create a new adapter class for setting data to each item of our Recycler View. For creating a new Java file, navigate to the app > java > your app’s package name > Right-click on it > New > Java File/Class and name it as CurrencyRVAdapter and add the below code to it. Comments are added in the code to get to know in more detail.
Step 9: Generating the API key and getting the URL for fetching data in JSON format
Go to the below link. After that, you simply have to sign up and create a new account on this website. After creating a new account simply sign in with your credentials and then you will get to see the below page.
On this page, we simply have to click on the Copy key option to copy your key. We have to use this key in our code in headers which are added below.
Step 10: 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.
Now run your app and see the output of the app