an android application program that converts the temperature from Celsius to Fahrenheit. Compile and build the project.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Week13" />
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Celsius to Fahrenheit"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter the temperature"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONVERT" />
</LinearLayout>
Wk13Activity.java:
package cse.wk13;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Wk13Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1=(TextView) findViewById(R.id.tv1);
TextView tv2=(TextView) findViewById(R.id.tv2);
TextView tv3=(TextView) findViewById(R.id.tv3);
final TextView tv4=(TextView) findViewById(R.id.tv4);
final EditText et=(EditText) findViewById(R.id.et);
Button btn=(Button) findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
String s1=et.getText().toString();
int cel=Integer.parseInt(s1);
float faren=(float) ((cel*1.8)+32);
String res=Float.toString(faren);
tv4.setText("Temperature in Fahrenheit is "+res);
}
});
}
}
Output:
Program Executed By:: Jyothi