Sajib_Ahmed

Untitled

Feb 14th, 2021
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.33 KB | None | 0 0
  1. package com.example.uc;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11.  
  12. public class ConversionActivity extends AppCompatActivity implements View.OnClickListener {
  13.     TextView textView,textView2,textView4,textView5,textView3,textView6;
  14.     EditText value1,value2,value3,value4,value5,value6;
  15.     Button button4, button5;
  16.     private String text1,text2;
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.conversion);
  21.         Intent intent = getIntent();
  22.          text1 = intent.getStringExtra("key1");
  23.          text2 = intent.getStringExtra("key2");
  24.  
  25.          value1=findViewById(R.id.value1);
  26.          value2=findViewById(R.id.value2);
  27.  
  28.         textView =findViewById(R.id.textView);
  29.         textView3=findViewById(R.id.textView3);
  30.         textView2 =findViewById(R.id.textView2);
  31.         textView4 =findViewById(R.id.textView4);
  32.         textView5 =findViewById(R.id.textView5);
  33.         textView6 =findViewById(R.id.textView6);
  34.  
  35.         button4=(Button) findViewById(R.id.button4);
  36.         button5=(Button) findViewById(R.id.button5);
  37.         textView.setText(text1);
  38.         textView2.setText(text2);
  39.         textView4.setText(text2);
  40.         textView5.setText(text1);
  41.         button4.setOnClickListener(this);
  42.         button5.setOnClickListener(this);
  43.  
  44.     }
  45.  
  46.     @Override
  47.     public void onClick(View v) {
  48.  
  49.  
  50.         if(text1.equals("Feet")) {
  51.             int id = v.getId();
  52.             if (id == R.id.button4) {
  53.  
  54.                 float num1 = Float.parseFloat(value1.getText().toString());
  55.                 float num3 = (float) (num1 / 3.28084);
  56.                 textView3.setText(String.valueOf(num3));
  57.                
  58.  
  59.             }
  60.             if (id == R.id.button5) {
  61.  
  62.                 float num1 = Float.parseFloat(value2.getText().toString());
  63.                 float num3 = (float) (num1 * 3.28084);
  64.                 textView6.setText(String.valueOf(num3));
  65.  
  66.                
  67.  
  68.             }
  69.         }
  70.  
  71.         if(text1.equals("Meter")) {
  72.             int id = v.getId();
  73.             if (id == R.id.button4) {
  74.  
  75.                 float num1 = Float.parseFloat(value1.getText().toString());
  76.                 float num3 = (float) (num1 * 100);
  77.                 textView3.setText(String.valueOf(num3));
  78.  
  79.             }
  80.             if (id == R.id.button5) {
  81.  
  82.                 float num1 = Float.parseFloat(value2.getText().toString());
  83.                 float num3 = (float) (num1 /100);
  84.                 textView6.setText(String.valueOf(num3));
  85.  
  86.  
  87.             }
  88.         }
  89.         if(text1.equals("KM")) {
  90.             int id = v.getId();
  91.             if (id == R.id.button4) {
  92.  
  93.                 float num1 = Float.parseFloat(value1.getText().toString());
  94.                 float num3 = (float) (num1 * 1000);
  95.                 textView3.setText(String.valueOf(num3));
  96.  
  97.             }
  98.             if (id == R.id.button5) {
  99.  
  100.                 float num1 = Float.parseFloat(value2.getText().toString());
  101.                 float num3 = (float) (num1 /1000);
  102.                 textView6.setText(String.valueOf(num3));
  103.  
  104.  
  105.             }
  106.         }
  107.  
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment