我有点疑惑。。
我有一个名为“结果”的变量,它是先前计算的变量的结果,然后附加 +10%、+20%、0%(与它相同..)-10% 等等,具体取决于哪个收音机用户选择的按钮,麻烦的是只有当用户点击按钮时才会计算数据。到目前为止,我的按钮工作正常:
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnCalcCalories:
double weight = Integer.parseInt(etWeight.getText().toString());
double bodyfat = Integer.parseInt(etBodyfat.getText().toString());
;
lbm = weight * (100 - bodyfat) / 100;
bmr = 370 + (21.6 * lbm);
maintCals = bmr * actLevel;
maintCalories.setText("Calories need to maintain current bodyweight: " + String.valueOf(maintCals));
lbmResult.setText("Your Lean Body Mass is " + String.valueOf(lbm)
+ "Kg");
bmrResult.setText("Your Base Metabolic rate is "
+ String.valueOf(bmr) + " calories");
calorieResult.setText("Your Daily calorie goal is " + String.valueOf(calResult) + " calories");
虽然我需要使用这样的无线电组来获取用户是否希望减轻/增加/保持体重:
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radLW:
setGPercentage = 10 * maintCals/100;
calResult = maintCals - setGPercentage;
break;
case R.id.radLWF:
setGPercentage = 20 * maintCals/100;
calResult = maintCals - setGPercentage;
break;
case R.id.radM:
setGPercentage = 0;
break;
case R.id.radGW:
setGPercentage = 10 * maintCals/100;
calResult = maintCals + setGPercentage;
break;
case R.id.radGWF:
setGPercentage = 20 * maintCals/100;
calResult = maintCals + setGPercentage;
break;
}
为了澄清,我需要根据用户选择的内容来计算“calResult”,显然如果变量仅在 onClick 方法期间计算,这可能是一个问题:/