Advertisement
Robert_JR

Currency Unit Conversion [USD & BDT]

Mar 6th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. //Rijoanul Hasan Shanto
  2. //Thursday, April 19, 2018
  3.  
  4. package com.example.robert_jr.myapplication;
  5.  
  6. import android.support.annotation.StringDef;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.RadioButton;
  13. import android.widget.RadioGroup;
  14. import android.widget.TextView;
  15.  
  16. public class MainActivity extends AppCompatActivity {
  17.  
  18.     private Button btnConvert;
  19.     private EditText edtValue;
  20.     private TextView txtAns;
  21.  
  22.  
  23.     private RadioButton getButton;
  24.     private RadioButton rbtnBtoU;
  25.     private RadioButton rbtnUtoB;
  26.  
  27.     @Override
  28.     protected void onCreate(Bundle savedInstanceState) {
  29.         super.onCreate(savedInstanceState);
  30.         setContentView(R.layout.activity_main);
  31.  
  32.         btnConvert = (Button) findViewById(R.id.btnConvert);
  33.         edtValue = (EditText) findViewById(R.id.edtValue);
  34.         txtAns = (TextView) findViewById(R.id.txtAns);
  35.  
  36.         rbtnBtoU = (RadioButton) findViewById(R.id.rbtnBtou);
  37.         rbtnUtoB = (RadioButton) findViewById(R.id.rbtnUtob);
  38.  
  39.         btnConvert.setOnClickListener(new View.OnClickListener() {
  40.             @Override
  41.             public void onClick(View v) {
  42.                 if(!new String(edtValue.getText().toString()).equals("") && edtValue.getText().toString().length() > 0)
  43.                 {
  44.                     String sval = edtValue.getText().toString();
  45.                     double val = Double.parseDouble(sval), result = 0.0;
  46.  
  47.                     if(rbtnBtoU.isChecked())
  48.                     {
  49.                         result = val / 83.8;
  50.                     }
  51.                     else if(rbtnUtoB.isChecked())
  52.                     {
  53.                         result = 83.8 * val;
  54.                     }
  55.  
  56.                     sval = String.valueOf(result);
  57.  
  58.                     txtAns.setText(sval);
  59.                 }
  60.                 else
  61.                 {
  62.                     txtAns.setText("Null");
  63.                 }
  64.                  //getButton.getText().toString());
  65.             }
  66.         });
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement