title: How to compare data(int) in the first and data(int) in second button in Android?
body: <p>I have a problem where I want to make the comparison the data in button</p>
  
  <pre><code>package lynn.calculate.KaunterKalori;
  
  import lynn.calculate.KaunterKalori.R;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.TextView;
  import android.widget.EditText;
  
  public class CalculateAll extends Activity implements OnClickListener {
  
  
  protected int totalKalori1;
  protected int totalKalori2;
  protected int totalKalori3;
  
  EditText EstimateCalorie;
  TextView TotalKaloriSehari;
  TextView totalsarapan;
  TextView totallunch;
  TextView totaldinner;
  TextView calorieneeds;
  TextView resultDiff;
  
  public CalculateAll() {
  
  }
  
  @Override
  public void onCreate(Bundle savedInstancesState) {
      super.onCreate(savedInstancesState);
      setContentView(R.layout.calculate_all);
  
      View kiraButton = findViewById(R.id.buttonKiraAll);
      kiraButton.setOnClickListener(this);
  
      View bezaButton = findViewById(R.id.caloriediff);
      bezaButton.setOnClickListener(this);
  
      TotalKaloriSehari = (TextView) findViewById(R.id.JumlahKalori);
      totalsarapan = (TextView) findViewById(R.id.sarapantext);
      totallunch = (TextView) findViewById(R.id.lunchtext);
      totaldinner = (TextView) findViewById(R.id.dinnertext);
      EstimateCalorie = (EditText) findViewById(R.id.BMR);
      // calorieneeds = (TextView) findViewById(R.id.BMR);
      resultDiff = (TextView) findViewById(R.id.result);
  
      Bundle extras = getIntent().getExtras();
      if (extras != null) {
          totalKalori1 = extras.getInt("totalBreakfast");
          totalKalori2 = extras.getInt("totalLunch");
          totalKalori3 = extras.getInt("totalDinner");
      }
  
      totalsarapan.setText(totalKalori1 + "");
      totallunch.setText(totalKalori2 + "");
      totaldinner.setText(totalKalori3 + "");
  
  
  
  }
  
  public void onClick(View v) {
      if (v.getId() == R.id.buttonKiraAll) {
  
  
       int TotalKalori = calculateTotalKalori(totalKalori1, totalKalori2,
                  totalKalori3);
          TotalKaloriSehari.setText(TotalKalori + "");
  
      }
  
      else if (v.getId()== R.id.caloriediff) {
  
          int nilaikalori = Integer.parseInt(EstimateCalorie.getText()
                  .toString());
  
  
          int bmr = calculatebmr(nilaikalori);
  
          String deskripsiKalori = describekalori(bmr);
          resultDiff.setText("kalori makanan" + TotalKalori + " calori  diperlukan " + bmr + "=" + deskripsiKalori); 
  // --&gt; this TotalKalori also can't be used
  
  
          Intent n = new Intent(this, MainActivity.class);
          startActivity(n);
  
      }
  
  }
  
  
  
  
  public int calculateTotalKalori(int totalKalori1, int totalKalori2,
          int totalKalori3) {
      return (int) (totalKalori1 + totalKalori2 + totalKalori3);
  
  }
  
  public int calculatebmr(int nilaikalori) {
      return (int) (nilaikalori);
  }
  
  private String describekalori(int bmr) { 
  
      if (bmr &lt; TotalKalori ) { //&lt;-- this TotalKalori can't be read/used
          return "bykkan makan";
      } else if (bmr == TotalKalori) {
  
          return "kekalkan jumlah kalori ini";
  
      } else if (bmr &gt; TotalKalori) {
  
          return "kurangkan pengambilan kalori";
  
      } else
          return "oiii";
  
  } 
  }
  </code></pre>
  
  <p>The first button, buttonKiraAll read int totalKalori, then i want to use the totalKalori data to be compare with 2nd data button calorieDiff, how i want to make the totalKalori can be read by the second button? so i can make the comparison </p>