document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.firstapp.helloworld;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. import android.widget.TextView;
  9.  
  10. public class HelloAndroidWorld extends Activity {
  11.     // inserite gli id che avete assegnato ai vostro oggetti
  12.     // nel main.xml
  13.     private EditText number1;
  14.     private EditText number2;
  15.     private TextView total;
  16.     private Button clickme;
  17.     // variabili per i calcoli
  18.     private int num1 = 0;
  19.     private int num2 = 0;
  20.     private int tot=0;
  21.  
  22.     /** Called when the activity is first created. */
  23.     @Override
  24.     public void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.main);
  27.         initControls();
  28.     }
  29.  
  30.     // inizializziamo i nostri oggetti
  31.     private void initControls() {
  32.         number1 = (EditText)findViewById(R.id.number1);
  33.         number2 = (EditText)findViewById(R.id.number2);
  34.         total = (TextView)findViewById(R.id.total);
  35.         clickme = (Button)findViewById(R.id.clickme);
  36.         // pulsante in attesa e pronto a lanciare la funzione calculate()
  37.         clickme.setOnClickListener(new Button.OnClickListener() {
  38.             public void onClick (View v){ calculate(); }});
  39.     }
  40.  
  41.     // funzione calculate che somma num1+num2 presi dalle
  42.     // EditText chiamate number1 e number2
  43.     // e riporta il risultato, tot, nella TextView total
  44.     private void calculate() {
  45.         num1=Integer.parseInt(number1.getText().toString());
  46.         num2=Integer.parseInt(number2.getText().toString());
  47.         tot=(num1+num2);
  48.         total.setText(Integer.toString(tot));
  49.     }
  50.  
  51. } // end
');