------------------------------------------------------------------------------------------------------------------------------
MainActivity.java
package com.example.celstofahr;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity{
private Button startB;
private String tempCels;
private TextView text;
private TextView display;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void calculate(View view ){
startB = (Button) this.findViewById(R.id.button);
text = (TextView) this.findViewById(R.id.editText);
tempCels = text.getText().toString();
int tempFahr = (int)(Double.parseDouble(tempCels)* 1.8 + 32);
display = (TextView) this.findViewById(R.id.textView);
display.setText(String.valueOf(tempFahr)+ "Fahrenheit");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
------------------------------------------------------------------------------------------------------------------------------
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="Degrees in Celsius">
<requestFocus />
</EditText>
<Button
android:id="@+id/button"
android:layout_width="274dp"
android:layout_height="wrap_content"
android:text="Convert"
android:onClick="calculate" />
<TextView
android:id="@+id/textView"
android:layout_width="275dp"
android:layout_height="wrap_content"
android:layout_weight="0.10"
android:text="Result" />
</LinearLayout>
------------------------------------------------------------------------------------------------------------------------------
Categories:
android,
app,
converter,
for,
temperature

