Advertisement
Guest User

Convertitor

a guest
May 27th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. package dibello.paolo.test;
  2.  
  3.  
  4. import android.app.Activity;
  5. import android.R.*;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.CheckBox;
  12. import android.widget.EditText;
  13. import android.widget.RadioButton;
  14. import android.widget.TextView;
  15. import android.widget.Toast;
  16.  
  17.  
  18. public class MainActivity extends Activity {
  19.  
  20.     EditText ed1;
  21.     TextView resu;
  22.     Button btn;
  23.     RadioButton ce_to_fa,fa_to_ce;
  24.  
  25.  
  26.  
  27.     @Override
  28.     protected void onCreate(Bundle savedInstanceState) {//Start of oncreate
  29.         super.onCreate(savedInstanceState);
  30.         setContentView(R.layout.activity_main); //Call layout
  31.  
  32.         //***Call View IDs allway before do some stuff with them
  33.         ed1=(EditText)findViewById(R.id.editText);
  34.  
  35.         resu=(TextView)findViewById(R.id.textView);
  36.  
  37.         ce_to_fa=(RadioButton)findViewById(R.id.radioButton);
  38.         fa_to_ce=(RadioButton)findViewById(R.id.radioButton2);
  39.  
  40.         btn=(Button)findViewById(R.id.button);
  41.  
  42.         //***Call View IDs end!
  43.  
  44.        show_toast("Ciao, guarda come sono educato!");
  45.  
  46.         btn.setOnClickListener(new View.OnClickListener() { //Start button click
  47.             @Override
  48.             public void onClick(View view) {
  49.  
  50.                 if(ed1.length()==1||ed1.length()>1){
  51.                     int a = Integer.parseInt(ed1.getText().toString()); //This is textbox one
  52.                     if(fa_to_ce.isChecked()){
  53.                         resu.setText(Double.toString((a-32.0) * 5.0/9.0)); //Show result to textview
  54.  
  55.                     }else(ce_to_fa.isChecked()){
  56.                         resu.setText(Double.toString((a*9.0)/5.0+32.0)); //Show result to textview
  57.  
  58.                     }
  59.  
  60.  
  61.                 }else{
  62.                     if(ed1.length()==0){
  63.                        //now i call show_toast and paste message there
  64.                         show_toast("Scrivere, casella vuota");
  65.                     }
  66.  
  67.                 }
  68.             }
  69.         });
  70.  
  71.     }
  72.  
  73.     public void show_toast(String message){
  74.         Toast.makeText(MainActivity.this,
  75.                 message, Toast.LENGTH_LONG).show();
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement