ボタンが int データを渡せないという問題があります。ここで
TotalKalori と bmr を比較したいコードですが、前のセクションで TotalKalori を解決できないようです。TotalKalori を変数に解決できないと言っています。これ?ありがとうございました
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 {
//private int TotalKalori;
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 + "");
}
if (v.getId()== R.id.caloriediff) {
int TotalKalori = calculateTotalKalori(totalKalori1, totalKalori2,
totalKalori3);
int nilaikalori = Integer.parseInt(EstimateCalorie.getText()
.toString());
//TotalKalori = Integer.parseInt(TotalKaloriSehari.getText().toString());
int bmr = calculatebmr(nilaikalori);
// String deskripsiKalori = describekalori(bmr);
// resultDiff.setText("kalori makanan" + TotalKalori + " calori diperlukan " + bmr + "=" + deskripsiKalori);
resultDiff.setText("kalori makanan = " + TotalKalori + " calori diperlukan = " + bmr);
}
}
//Intent n = new Intent(this, MainActivity.class);
//startActivity(n);
//
private String describekalori(int bmr) {
if (bmr < TotalKalori ) {
return "bykkan makan";
} else if (bmr == TotalKalori) {
return "kekalkan jumlah kalori ini";
} else if (bmr > TotalKalori) {
return "kurangkan pengambilan kalori";
} else
return "oiii";
}
public int calculateTotalKalori(int totalKalori1, int totalKalori2,
int totalKalori3) {
return (int) (totalKalori1 + totalKalori2 + totalKalori3);
}
public int calculatebmr(int nilaikalori) {
return (int) (nilaikalori);
}
}
// the comparison that I can't solve is the
// the TotalKalori cannot resolved into variable? how do I solve this? thank you
private String describekalori(int bmr) {
if (bmr < TotalKalori ) {
return "bykkan makan";
} else if (bmr == TotalKalori) {
return "kekalkan jumlah kalori ini";
} else if (bmr > TotalKalori) {
return "kurangkan pengambilan kalori";
} else
return "oiii";
}