Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Android Temperature Converter App



A basic android app with an objective of learning how to use

1. Textbox
2. RadioGroup
3. Button

Download Project Here

Convert.java
package and.temperature;

import android.app.Activity;


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class Convert extends Activity {

private EditText textInput;
private TextView textOutput;
private RadioGroup rdGroup;
private Float temp=0f;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textInput=(EditText)findViewById(R.id.textTemp);
textOutput=(TextView)findViewById(R.id.textOutput);
rdGroup=(RadioGroup)findViewById(R.id.radioGroup);
}

public void myClickHandler(View view){
switch(view.getId()){
case R.id.Button01:

try{
temp=new Float(textInput.getText().toString());

switch(rdGroup.getCheckedRadioButtonId())
{
case R.id.radioCelcius:
textOutput.setText(Float.toString(FarenhiteToCelcius(temp))+" C");
break;

case R.id.radioFarenhite:
textOutput.setText(Float.toString(CelciusToFarenhite(temp))+" F");
break;
}
}catch(Exception e)
{
Toast.makeText(this, "Invalid Input",
Toast.LENGTH_LONG).show();
}

break;

}
}

public float FarenhiteToCelcius(float temp){
return ((temp - 32) * 5 / 9);
}

public float CelciusToFarenhite(float temp){
return ((temp * 9) / 5) + 32;

}

public void Close(View view){

// Bundle bd = i.getExtras();
// if(bd.getInt("Close") == 1);

finish();
Log.v("DISPLAY", "closing convert");
}
}


Download Project Here


This post first appeared on Handsome Android, please read the originial post: here

Share the post

Android Temperature Converter App

×

Subscribe to Handsome Android

Get updates delivered right to your inbox!

Thank you for your subscription

×