Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. package com.example.aasemjs.weightconverter;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.EditText;
  7. import android.widget.Toast;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11.  
  12. public void cnvPounds(View view){
  13.  
  14. EditText weightInKg = (EditText) findViewById(R.id.edTxtKg);
  15.  
  16. String strKg = weightInKg.getText().toString();
  17.  
  18. Double dblKg = Double.parseDouble(strKg);
  19.  
  20. Double PoundsAmount = dblKg * 2.20462;
  21.  
  22. Toast.makeText(getApplicationContext(), "Weight in pounds = " + PoundsAmount + "lbs", Toast.LENGTH_LONG).show();
  23. }
  24.  
  25. public void cnvKgs(View v){
  26.  
  27. EditText weightInLbs = (EditText) findViewById(R.id.edtTxtLbs);
  28.  
  29. String strLbs = weightInLbs.getText().toString();
  30.  
  31. Double dblLbs = Double.parseDouble(strLbs);
  32.  
  33. Double KgAmount = dblLbs * 0.453592;
  34.  
  35. Toast.makeText(getApplicationContext(), "Weight in pounds = " + KgAmount + "kg", Toast.LENGTH_LONG).show();
  36. }
  37.  
  38. @Override
  39. protected void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. setContentView(R.layout.activity_main);
  42. }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement