Skip to content

Instantly share code, notes, and snippets.

@Butch78
Created September 17, 2017 03:57
Show Gist options
  • Save Butch78/3a1f3ac8b20fa0d95af5e1be3bb383c8 to your computer and use it in GitHub Desktop.
Save Butch78/3a1f3ac8b20fa0d95af5e1be3bb383c8 to your computer and use it in GitHub Desktop.
Conversion App
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matthew.myconversionapp.distConversion">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="26dp"
android:layout_marginTop="4dp"
android:text="@string/convert_to_metric"
app:layout_constraintLeft_toLeftOf="@+id/editTextInches"
app:layout_constraintTop_toBottomOf="@+id/editTextInches"
tools:ignore="MissingConstraints"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
<EditText
android:id="@+id/editTextMiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:labelFor="@+id/editTextMiles"
tools:ignore="LabelFor"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="18dp"
app:layout_constraintTop_toBottomOf="@+id/textViewMiles"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:id="@+id/editTextFeet"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextInches"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="14dp"
app:layout_constraintTop_toBottomOf="@+id/TextViewInches"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="@+id/editTextFeet" />
<TextView
android:id="@+id/textViewConvertedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="74dp"
tools:ignore="RtlHardcoded"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="47dp"
app:layout_constraintLeft_toLeftOf="parent" />
<TextView
android:id="@+id/textViewMiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="41dp"
android:text="@string/miles"
android:textSize="24sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<TextView
android:id="@+id/TextViewFeet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="29dp"
android:autoText="false"
android:maxLines="1"
android:text="@string/feet"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/editTextFeet"
app:layout_constraintLeft_toLeftOf="@+id/editTextFeet"
app:layout_constraintRight_toRightOf="@+id/editTextFeet"
tools:ignore="TextViewEdits"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
<TextView
android:id="@+id/TextViewInches"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:text="@string/inches"
android:textSize="24sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextFeet"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/togglebutton"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="36dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="20dp" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matthew.myconversionapp.MainActivity">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="92dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_weight="0.52"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="MissingConstraints"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1">
<Button
android:id="@+id/tempButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.52"
android:text="@string/temerature_conversion"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="0dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="115dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="19dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
app:layout_constraintHorizontal_bias="0.849"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.273"
tools:ignore="MissingConstraints"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<Button
android:id="@+id/distButton"
android:layout_width="match_parent"
android:layout_height="77dp"
android:layout_weight="0.52"
android:text="@string/distance_conversion"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matthew.myconversionapp.tempConversion"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<TextView android:id="@+id/celciusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="@string/celcius"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="93dp"
android:layout_marginTop="59dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText android:id="@+id/inputTempEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="numberSigned|numberDecimal"
android:text="@string/_1"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
app:layout_constraintRight_toRightOf="@+id/celciusTextView"
android:layout_marginTop="29dp"
app:layout_constraintTop_toBottomOf="@+id/celciusTextView"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="@+id/celciusTextView" />
<Button
android:id="@+id/convertButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="93dp"
android:layout_marginStart="93dp"
android:text="@string/convert"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1" />
<TextView android:id="@+id/convertedTempTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="48sp"
android:text="@string/_000f"
android:layout_marginStart="21dp"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="@+id/convertButton"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="46dp"
app:layout_constraintLeft_toLeftOf="@+id/convertButton" />
</android.support.constraint.ConstraintLayout>
package com.example.matthew.myconversionapp;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class distConversion extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dist_conversion);
initializeUI(savedInstanceState);
// How to output Log.i("WORK MY MAN", "TESTd");
}
private void initializeUI(Bundle savedInstanceState)
{
// Call Restores State
restoreState(savedInstanceState);
Button button = (Button) findViewById(R.id.button1);
ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ConvertValue();
}
});
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
TextView convertedText = (TextView) findViewById(R.id.textViewConvertedText);
if (isChecked) {
convertedText.setText(String.valueOf(ConvertValue()/ 100) + " Metres");
} else {
convertedText.setText(String.valueOf(ConvertValue()) + " CM");
}
}
});
}
//Restores the State of the Value.
private void restoreState(Bundle state)
{
if(state == null)
return;
EditText inputTempTextMiles = (EditText) findViewById(R.id.editTextMiles);
EditText inputTempTextFeet = (EditText) findViewById(R.id.editTextFeet);
EditText inputTempTextInches = (EditText) findViewById(R.id.editTextInches);
TextView convertedText = (TextView) findViewById(R.id.textViewConvertedText);
String inputMiles = state.getString("inputMiles");
String inputFeet = state.getString("inputFeet");
String inputInches = state.getString("inputInches");
String convertText = state.getString("convertDist");
inputTempTextMiles.setText(inputMiles);
inputTempTextFeet.setText(inputFeet);
inputTempTextInches.setText(inputInches);
convertedText.setText(convertText);
}
// Saves the Input Text on Rotate.
@Override
public void onSaveInstanceState(Bundle state)
{
EditText inputTempTextMiles = (EditText) findViewById(R.id.editTextMiles);
EditText inputTempTextFeet = (EditText) findViewById(R.id.editTextFeet);
EditText inputTempTextInches = (EditText) findViewById(R.id.editTextInches);
TextView convertedText = (TextView) findViewById(R.id.textViewConvertedText);
//Converting the inputs to Strings
String inputTextMiles = inputTempTextMiles.getText().toString(); //Miles Input
String inputTextFeet = inputTempTextFeet.getText().toString(); //Feet input
String inputTextInches = inputTempTextInches.getText().toString(); //Inches input
//Converting result to String
String convertText = convertedText.getText().toString();
// Saving the Inputs
state.putString("inputMiles", inputTextMiles);
state.putString("inputFeet", inputTextFeet);
state.putString("inputInches", inputTextInches);
state.putString("convertDist", convertText);
super.onSaveInstanceState(state);
}
private double ConvertValue()
{
EditText inputTempTextMiles = (EditText) findViewById(R.id.editTextMiles);
EditText inputTempTextFeet = (EditText) findViewById(R.id.editTextFeet);
EditText inputTempTextInches = (EditText) findViewById(R.id.editTextInches);
double miles = 0.0;
double feet = 0.0;
double inches = 0.0;
if (inputTempTextMiles.length()>0){
miles = Double.parseDouble(inputTempTextMiles.getText().toString());
}
else if (inputTempTextInches.length()>0)
{
inches = Double.parseDouble(inputTempTextInches.getText().toString());
}
else if (inputTempTextFeet.length()>0)
{
feet = Double.parseDouble(inputTempTextFeet.getText().toString());
}
double totalInches = (((miles * 5280) + feet) * 12) + inches;
return totalInches * 2.54;
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matthew.myconversionapp.distConversion"
tools:layout_editor_absoluteY="73dp"
tools:layout_editor_absoluteX="0dp">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert To Metric"
tools:ignore="MissingConstraints"
android:layout_marginEnd="57dp"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="51dp" />
<EditText
android:id="@+id/editTextMiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:labelFor="@+id/editTextMiles"
tools:ignore="LabelFor"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="@+id/editTextFeet"
android:layout_marginTop="16dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="@+id/editTextFeet"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:id="@+id/editTextFeet"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="@+id/editTextInches"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/editTextMiles"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="@+id/editTextInches" />
<EditText
android:id="@+id/editTextInches"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
android:layout_marginStart="11dp"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="29dp"
app:layout_constraintTop_toBottomOf="@+id/editTextFeet"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toRightOf="@+id/TextViewInches" />
<TextView
android:id="@+id/textViewConvertedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="33dp"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/TextViewInches"
app:layout_constraintRight_toLeftOf="@+id/editTextInches"
tools:ignore="RtlHardcoded"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
<TextView
android:id="@+id/textViewMiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Miles"
android:textSize="24sp"
android:layout_marginStart="35dp"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="16dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/TextViewFeet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoText="false"
android:maxLines="1"
android:text="Feet"
android:textSize="24sp"
tools:ignore="TextViewEdits"
android:layout_marginEnd="23dp"
app:layout_constraintRight_toLeftOf="@+id/editTextFeet"
tools:layout_constraintRight_creator="1"
app:layout_constraintBaseline_toBaselineOf="@+id/editTextFeet"
tools:layout_constraintBaseline_creator="1" />
<TextView
android:id="@+id/TextViewInches"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inches"
android:textSize="24sp"
android:layout_marginStart="36dp"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="5dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/editTextInches" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:layout_marginStart="11dp"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="@+id/editTextInches"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toRightOf="@+id/editTextFeet" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.matthew.myconversionapp.tempConversion"
tools:layout_editor_absoluteY="73dp"
tools:layout_editor_absoluteX="0dp">
<TextView android:id="@+id/celciusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="@string/celcius"
android:layout_marginStart="93dp"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="49dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText android:id="@+id/inputTempEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="numberSigned|numberDecimal"
android:text="@string/_1"
android:layout_marginStart="28dp"
android:layout_marginEnd="28dp"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="@+id/celciusTextView"
android:layout_marginTop="29dp"
app:layout_constraintTop_toBottomOf="@+id/celciusTextView"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="@+id/celciusTextView" />
<Button
android:id="@+id/convertButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="93dp"
android:text="@string/convert"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="51dp"
app:layout_constraintLeft_toLeftOf="parent" />
<TextView android:id="@+id/convertedTempTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="48sp"
android:text="@string/_000f"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginEnd="160dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="107dp"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
package com.example.matthew.myconversionapp;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button distButton = (Button) findViewById(R.id.distButton);
Button tempButton = (Button) findViewById(R.id.tempButton);
//Button that leads to the Distance conversion application
distButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent navIntent = new Intent();
navIntent.setClass(getApplicationContext(), distConversion.class);
startActivity(navIntent);
}
});
//Button that leads to the Temperature conversion application
tempButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent navIntent = new Intent();
navIntent.setClass(getApplicationContext(), tempConversion.class);
startActivity(navIntent);
}
});
}
}
package com.example.matthew.myconversionapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class tempConversion extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_temp_conversion);
initializeUI(savedInstanceState);
}
private void initializeUI(Bundle savedInstanceState)
{
Button convertButton = (Button) findViewById(R.id.convertButton);
// Call Restores State
restoreState(savedInstanceState);
convertButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ConvertToFh();
}
});
}
//Restores the State of the Value.
private void restoreState(Bundle state)
{
if(state == null)
return;
EditText inputTempText = (EditText) findViewById(R.id.inputTempEditText);
TextView convertedText = (TextView) findViewById(R.id.convertedTempTextView);
String convertTemp = state.getString("ConvertTemp");
String inputTemp = state.getString("inputTemperature");
convertedText.setText(convertTemp);
inputTempText.setText(inputTemp);
}
// Saves the Input Text on Rotate.
@Override
public void onSaveInstanceState(Bundle state)
{
EditText inputTempText = (EditText) findViewById(R.id.inputTempEditText);
TextView convertedText = (TextView) findViewById(R.id.convertedTempTextView);
String inputText = inputTempText.getText().toString(); //Celsius Temp
String outputText = convertedText.getText().toString(); //converted Text
//Saving Input and Converted Text
state.putString("inputTemperature", inputText);
state.putString("ConvertTemp", outputText);
super.onSaveInstanceState(state);
}
private void ConvertToFh()
{
EditText inputTempText = (EditText) findViewById(R.id.inputTempEditText);
String strOutput = "ERR";
//Gets the entered value and converts it to a double
double c = Double.parseDouble(inputTempText.getText().toString());
//Conversion of the input Data to fahrenheit
double f = c * (9.0/5.0) + 32.0;
strOutput = String.format("%.2f F", f);
TextView convertedText = (TextView) findViewById(R.id.convertedTempTextView);
convertedText.setText(strOutput);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment