How to Build Decimal to Hexadecimal Converter Android App in Android Studio?
In this article, we would be learning how to make a Decimal to Hexadecimal Converter App in Java in Android Studio. This app would take an input of a Decimal number, convert it into a Hexadecimal number and then show the output. So let’s go through the brief go through of how we would be making the app.
Brief Go through
We will begin by first creating the drawable resource file and working with the XML of it to give an outline to the Edit Texts which we will be implementing further. After that we will be working with the activity_main.xml, where we would be adding two Edit Texts, one for taking the input of decimal number and another for showing the output, two buttons for submitting which will submit the input and clear to reset it and then two Text Views to show some instructions to the user of how to use the app. At the last, we would be working with the MainActivity.java, where we implement some functions which would do the whole conversion when the user clicks on the buttons. Note that we are going to implement the whole application in the Java programming language. Below is the sample gif of the working app which will give you an idea of what we will are going to make in this article.
Step by Step Implementation
Step 1: Create a New Project with an Empty Activity
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. We would first select a Project Template and then Configure our project by giving the name and choosing the language in which we are making the app. Note that select Java as the programming language.
Step 2: Adding a new Drawable Resource File
In this step, we would be adding a new drawable resource file by navigating to app/res/drawable and then right-click on the drawable folder and go to New/Drawable Resource File.
Now, we would name the drawable resource file and select the root element as a shape. With the remaining default settings click on the “ok” button. Note that while naming the resource file, the name should not contain any capital letters.
Step 3: Working with the Drawable Resource File
After creating the drawable resource file in the previous step, now we have to write some code in the XML such that it will give the outline to the EditText. First of all, we will define the shape as a “rectangle“. Then add a stroke to the shape which will make an outline around the shape. Under the same attribute, we will specify the width and color of the stroke. Finally, we will give a round shape in the corners by specifying the radius of the corners. Refer to the XML code below to understand the above lines:
Step 4: Working with the activity_main.xml file
Navigate to the app/res/layout/activity_main.xml and add the below code to that file. In the activity_main.xml file, we have to add two EditText for Input and Output text to display, two buttons for submitting which will submit the input and clear to reset it and we have added two TextView to show some text so that we can guide the user about how to use this app. Below is the code for the activity_main.xml file.
After writing the code of the XML file for the app, the design will look something like this:
Step 5: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Comments are added inside the code to understand the code in more detail.