Build a temperature conversion application in Android Studio
11 minute(s) read | Published on: Apr 21, 2021 Updated on: Dec 14, 2021 |
In this case, you do not need any physical devices and hardware to test and review the application. You can easily check and test the operating system and application using the application environment simulator. Android SDK toolbox has Android Device Emulator simulation tools and software that can simulate the application environment. The user can easily simulate the application environment and operating system using this software.
AVDs allow you to simulate the environment of different applications without the need for hardware or device. Even if you have the necessary hardware and device, it is better to learn how to work with this simulator software. When using AVDs, the user determines the configuration of the virtual machine. Configuration includes screen resolution and density.
You can even create multiple AVDs and run them simultaneously and in parallel. By doing this, you can also configure different devices simultaneously.
Note: You should note that if you stop the AVD while operating, it will cause the program to crash. It takes about 10 minutes for an app to launch and run for the first time and about 3 minutes for newer devices.
Once you have launched the AVD and come up, it is time to design and configure the GUI.
Android emulator shortcuts
The shortcuts for doing some things in this emulator software are as follows:
- Alt + Enter:
They are used to zoom in on Android emulator software.
- Ctrl + F11:
They are used to change the screen orientation from landscape to portrait mode or vice versa.
- F8:
It was used to turn the network on or off.
simulator speed optimization
When creating a simulator to simulate the application environment, two options are shown to you to choose one of them. Snapshot and Use Host GPU options Note: You may think you can select both when a window appears to select two options. But in reality, this is not the case, and you can only choose one option. If you select both options, you will encounter an error message.
Snapshot:
If you select this option when creating the emulator, it will load at high speed for the second time you want to run the emulator and simulate the application environment. The high speed of loading the simulator for the second time is because the first time all the necessary information and device modes are stored, and there is no need for further review and processing.
Use Host GPU:
When creating the emulator, if this option is your choice, the speed will increase significantly. Because AVD removes all the information from the graphics card on the host computer speeds it up.
Intel system image
You may want to run AVD with an image based on the ARM CPU and Intel CPI architecture.
It should be noted that AVD, which uses the Intel video system based on the Intel CPI architecture and Intel / AMD hardware, is much faster than the video system based on the Intel / AMD architecture. This speed is because the emulator does not need to read, process, and translate ARM CPU commands accurately.
The video system we talked about can be installed through the AndroidSDK Manager:
After downloading it, you can find the relevant driver in the extras/intel file where Android is installed. Note: You must note that you must perform the driver installation process successfully, and it is not enough just to download them. Downloading is not enough, and you must install them after downloading.
Get started with AndroidStudio.
In this part of Android Studio training, we first create an Android application and then use Android Studio to simulate it in its respective environment.
How to create a new Android-project?
1- Click on Start a new Android Studio project.
2- Then, enter the requested information. Information such as project name and ...
3- In the next step, select the invoice form you want.
4- Then agree to the terms and conditions of the licenses.
5- By doing the above steps, you can do the process of downloading the Android SDK.
6- After completing the SDK download steps, click on Blank Activity.
7- After creating Blank Activity, you first need to define a new AVD.
8- To do this, you can open AVD Manager and go to Tools → Android → AVD Manager.
9- Then click on the Create Virtual Device ... button.
10- Specify and adjust the size of the AVD screen.
11- Then, enter the appropriate name for the AVD.
12- Then click on Finish.
13- By doing this, we perform all the configurations related to AVD and display them under virtual devices.
14- To launch and run AVD, after selecting AVD, click the Play button.
15- To launch the application, you can go running → Run 'app'.
16- Then, a window will open for you in which you must select the device on which you want the application to be simulated.
How to build an application using AndroidStudio?
In this part of the tutorial, we will create an application used to convert temperature and convert temperature. If you want to create an application that can convert temperature for you, it is recommended to follow the continuation of this tutorial. Using Android Studio, we create an application.
In the first step, you must create a project to do the necessary programming to design and build the application. It is better to enter all the required information more carefully to finally create a project. The table below contains information you can enter in the fields and information requested by you. According to this training article, it is better to pay attention to the values listed in the table below if you want to move forward.
The number of properties
- Application name:
Temperature Converter
- Package name:
De. vogella. Android. temperature
- user interface version:
The latest version of the API (Minimum, Target, Compile with)
- template:
Empty Activity
- Activity:
MainActivity
- Layout:
activity_main
According to the information and values listed in this table, you can also respond to all the information requested when creating a project.
Attribute on its
Allows you to apply some attributes such as strings and colors or Static Resources in general. To apply these attributes, you can use them in XML files separately or with Java source code.
You must first open the res/values / strings.xml file so that you can finally access the editor of that file.
1-For example, you want to change the color attribute or attribute or apply it from scratch. To do this, you must click the Add button.
2- Then select the Color option from the lists that it shows you and click the ok button.
3- Then, enter the myColor value for the name field. This value is selected and applied as the color name.
4- Enter # F5F5F5 for the color value as well. This value represents the color and combines and creates the color you want.
5- Then, you have to refer to the XML file and make sure that the entered values are entered correctly or not.
6- The code inserted below indicates the state and status after applying the changes to select and apply the color attribute.
Use the layout editor.
1- To use the outline editor, you must first open the res/layout / activity_main.xml file.
2- You have to double click on it to open the Android editor for you.
3- By opening the Android Studio editor, you can add and drag all the elements you want to have on the page and need to design the user interface to the page by dragging and dropping or so-called drag & drop.
4- Another way you can use it to create the outline of the page and apply changes to it is to use XML source code. You can apply all the changes you want to the page via XML source code.
5- To be able to more easily and more know the elements and elements of the view and easily use them on the page, it is recommended to change their display type. Change so that you can see their icons and their names and posts. In this case, you can easily choose which element to use. Show icons and text is the best mode you can choose.
How to add views to a layout file?
In this part of the tutorial, we create and design the application user interface, which is an important part of the application development process.
1- There is a text inside the layout file, Hello World! Right-click on this text.
2- After right-clicking, a popup menu will appear for you. Select Delete from the popup menu to delete the text object.
3- Click on the Text Field to see all the text fields.
4- Select the Plain Text tool from the text fields you see and add it to your page using the popular mouse drag and drop method.
5- You create a text input field by adding that widget to the layout.
6- You have to select the Form Widgets option from the Palette section, drag RadioGroup into the page and add it.
7- The number of radio buttons that will be on your page varies, but it is better to have two radio buttons inside your page.
8- Select a Button from the Form Widgets section, refer to it with the layout method, open its XML tab and compare it with the following code and text.
All the components you used to design the user interface are in the layout file.
9- add background color to the layout file. To continue and select the color using the code method, do the following.
After you change the background color according to the codes listed above, your background color will change to WhiteSmoke. Of course, choosing and changing the background color is a matter of taste, and if you want, you can choose and change it to your liking. The color in this tutorial is WhiteSmoke.
10- Now, you need to go to the activity_main.xml tab to ensure your XML file is correct.
11- Compare and match the items in the activity_main.xml tab.
How to create a utility class?
By creating a utility class, you convert Celsius to Fahrenheit and vice versa. We need to create a utility class for the application we want to design to perform the temperature conversion operation well.
Creates the code inserted below the utility class and the temperature change operation from Celsius old. Temperature:
Activity codes
By default, the MainActivity class for the activity code is created using the Android Studio wizard. It is better to modify the activity code as follows.
The codes listed below are for modifying activity codes. It is better to compare and change all of them with your activation codes.
Note: onClick is called by clicking the button.
Launch the app
To run the created application and view it inside the simulation environment of the simulator software, you must right-click on the desired project and then select the Run-As → Android Application options. In this case, your application will run, and its environment will be displayed inside the emulator software.
To test the designed application inside the simulator software environment, you can enter a number and view the temperature conversion from Fahrenheit to Celsius and vice versa.
In this educational article, you get acquainted with Android Studio, its environment, and how to build an application. In this article, you could design an application that converts temperature using Android Studio.
About our Android and iOS app development services