Advertisement
Guest User

ResultActivity

a guest
Apr 4th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.14 KB | None | 0 0
  1. package com.example.testexample;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.constraintlayout.widget.ConstraintLayout;
  5.  
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.TextView;
  11.  
  12. import javax.xml.transform.Result;
  13.  
  14. public class ResultActivity extends AppCompatActivity {
  15.  
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_result);
  20.         ConstraintLayout conlay;
  21.         TextView textView1 = (TextView) findViewById(R.id.ResultTxt);
  22.         TextView txtview2 = (TextView) findViewById(R.id.TxtGender);
  23.         Intent intent = getIntent();
  24.         double Hinput = intent.getIntExtra(MainActivity.EXTRA_HINPUT,0);
  25.         double Winput = intent.getIntExtra(MainActivity.EXTRA_WINPUT,0);
  26.         String maletxt = intent.getStringExtra(MainActivity.EXTRA_MALE);
  27.         String femaletxt = intent.getStringExtra(MainActivity.EXTRA_FEMALE);
  28.         String gender;
  29.         double calc = (Winput / (Hinput * Hinput)) * 10000;
  30.         int result = (int) calc;
  31.  
  32.         conlay = findViewById(R.id.constraintLayout);
  33.  
  34.         switch(gender){
  35.             case maletxt:
  36.                 if(result <= 18.5){
  37.                     conlay.setBackgroundResource(R.drawable.underresult);
  38.                 }
  39.                 else if ( result >= 18.6 && result <= 24.9){
  40.                     conlay.setBackgroundResource(R.drawable.normalresult);
  41.                 }
  42.                 else if ( result >= 25.0 && result <= 29.9){
  43.                     conlay.setBackgroundResource(R.drawable.overresult);
  44.                 }
  45.                 else if ( result >= 30 && result <= 39.9){
  46.                     conlay.setBackgroundResource(R.drawable.obesresult);
  47.                 }
  48.                 else if( result >= 40.0){
  49.                     conlay.setBackgroundResource(R.drawable.dresult);
  50.                 }
  51.  
  52.                 textView1.setText("" + result);
  53.                 break;
  54.  
  55.             case femaletxt:
  56.                 txtview2.setText("FEMALE");
  57.                 if(result <= 18.5){
  58.                     conlay.setBackgroundResource(R.drawable.underresult);
  59.                 }
  60.                 else if ( result >= 18.6 && result <= 24.9){
  61.                     conlay.setBackgroundResource(R.drawable.normalresult);
  62.                 }
  63.                 else if ( result >= 25.0 && result <= 29.9){
  64.                     conlay.setBackgroundResource(R.drawable.overresult);
  65.                 }
  66.                 else if ( result >= 30 && result <= 39.9){
  67.                     conlay.setBackgroundResource(R.drawable.obesresult);
  68.                 }
  69.                 else if( result >= 40.0){
  70.                     conlay.setBackgroundResource(R.drawable.dresult);
  71.                 }
  72.  
  73.                 textView1.setText("" + result);
  74.  
  75.             default:
  76.                 textView1.setText(""+ result);
  77.         }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.         //Sharing Codes Below//
  84.         Button bt;
  85.         bt=(Button)findViewById(R.id.sharebtn);
  86.         bt.setOnClickListener(new View.OnClickListener() {
  87.  
  88.  
  89.             @Override
  90.             public void onClick(View v) {
  91.                 Intent myIntent = new Intent(Intent.ACTION_SEND);
  92.                 myIntent.setType("text/plain");
  93.                 String shareBody = "Your body here";
  94.                 String shareSub = "Your subject here";
  95.                 myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
  96.                 myIntent.putExtra(Intent.EXTRA_TEXT,shareBody);
  97.                 startActivity(Intent.createChooser(myIntent, "Share using"));
  98.  
  99.             }
  100.         });
  101.         //Sharing codes End here//
  102.  
  103.         //Open BMI TABLE is below//
  104.         Button tblbtn;
  105.         tblbtn=(Button)findViewById(R.id.BmiTblBtn);
  106.         tblbtn.setOnClickListener(new View.OnClickListener() {
  107.             @Override
  108.             public void onClick(View v) {
  109.                 startActivity(new Intent(ResultActivity.this, BmiTableActivity.class));
  110.             }
  111.         });
  112.         //Open BMI TABLE Codes End here//
  113.  
  114.  
  115.  
  116.  
  117.     }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement