How to Build a Decimal to Binary Converter Android App in Android Studio?
This app will convert a Decimal Number into a Binary Number. Some people may also have written a java program to convert a Decimal Number into Binary Number, but while making an app let’s see how to do that.
Brief Go through
We will start by creating a new project with an Empty Activity. After creating a project, we would add the drawable resource file which will be used to give a box-type shape or outline to the EditText. Then we would work with the XML file where we would be adding two EditTexts, Buttons, and TextViews. In the final, we will go to the MainActivity.java and create some functions which will work when the user will click on the buttons. Note that we are going to implement the application using the Java language. A sample gif is given below to get an idea of what we are going to implement 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. Note that select Java as the programming language.
Step 2: Adding a drawable resource file
Navigate to app/res/drawable and right-click on the drawable folder and go to New/Drawable Resource File.
Name the file as “edit_text_border” (you can name anything according to your wish but note that the letters should not be in the capital) and with the default settings, click on the ok button.
Step 3: Working with the drawable resource file
In the XML file of the drawable resource “edit_text_border.xml”, we will define the shape as a rectangle first. 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 submit which will submit the input and clear to reset it and I 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 ActivityMain.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.