In this application we are going to build a simple temperature converter. It will calculate to two decimal places.
For reference, here are the forumala’s needed.
In order to accomplish this we are going to build an activity named TemperatureActivity and a layout called activity_temperature. The layout will contain an EditText for numerical input that has hint text to explain to the user what’s expected and will take decimal numbers.
Next, create a RadioGroup with two RadioButton’s so the user can choose the temperature to convert to.
Now we’ll create a convert button with an onClick property on it.
Lastly, we need a place to display our result. We can do this in a simple TextView.
Now that we have everything laid out, let’s go back to TemperatureActivity and wire everything together.
Now we can make an onClickListener that calls one of two methods to convert the given temperature based on the radio button. It also does some error checking and displays a Toast to give the user some feedback if they’ve done something wrong. Finally, if everything is entered properly, the converted value gets stored to the TextView.
Lastly, here are the two conversion methods based on the formula given above.