Tuesday, May 18, 2010

K Nex Big Air Ball Tower Ebay



Creating an application that can convert temperature from ° C to ° F and vice versa

Senza titolo ConvertiTemperatura.java Senza titolo2 ---------------- ----------------- -

package org.me.convertitemperatura; android.os.Bundle;

android.app.AlertDialog.Builder import, import

android.widget .*;

import android.view . View;

import android.content.Intent;

import android.app.AlertDialog; import android.content.Context; /**

*

* @author lollino360

*/

public class ConvertiTemperatura extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView (R.layout.main)
/ / TODO add your GUI initialization code here
& # 160;} public void
conv1 (View view) {
& # 160; EditText number1 = (EditText) findViewById (R.id.t1)
; numero2 = edit text (alt text) findViewById (R.id.t2)
& # 160; try {
& # 160; double num1 = Double.parseDouble (numero1.getText (). toString ());
& # 160; double res = num1 * 1.8 +32;
String result = "" + res;
; numero2.setText (result);
& # 160; ; } Catch (NumberFormatException e) {
& # 160; e.printStackTrace ();
& # 160; ; numero2.setText ("You must enter a number ");
& # 160;}}
public void
conv2 (View view) {
EditText number1 = (EditText) findViewById (R.id.t1)
numero2 edit text = (text edit) findViewById (R.id.t2)
try {
, & # 160; double num2=Double.parseDouble(numero2.getText().toString());
            double ris=(num2-32)/1.8;
            String risultato=""+ris;
            numero1.setText (result);
& # 160;} catch (NumberFormatException e) {
e.printStackTrace ();
; numero1.setText ("You must enter a number!");
& # 160;
}}}



main.xml
----------------- ----------- ------

\u0026lt;? xml version = "1.0" encoding = "UTF-8"?>
\u0026lt;TableLayout xmlns: android = "
http://schemas.android.com / apk / res / android "android

: layout_width =" fill_parent "
android: layout_height = "fill_parent"
android: stretch columns = "1"

>

\u0026lt;TableRow> ; \u0026lt; EditText android: layout_width = "200px"

android: layout_height = "wrap_content"

android: id = "@ + id/t1"
& # 160; /> ; \u0026lt;TextView android: text = "° C" android: layout_width = "100px"
& # 160; />
\u0026lt;/ TableRow>
& # 160; \u0026lt;TableRow>
\u0026lt;EditText
& # 160; android: layout_width = "200px" android
: layout_height = "wrap_content"
android: id = "@ + id/t2"
/ >
\u0026lt;TextView android: text = " ° F "& #
160; android: layout_width = "100px"
, / >
\u0026lt;/ TableRow>
\u0026lt;Button android: id = "@ + id / Converti"
& # 160; android: layout_width = "fill_parent"
; android: layout_height = "wrap_content"
& # 160; android: text = "Converti in ° F"
; android: onClick = "CONV1"
/>
\u0026lt;Button android: id = "@ + id/converti2"
& # 160; android: layout_width = "fill_parent"
& # 160; android: layout_height = "wrap_content"
& # 160; android: text = "Converti in ° C"
; android: onClick = "CONV2"
/>
\u0026lt;/ TableLayout>











0 comments:

Post a Comment