问题:当我将应用程序的结果与bmi网站进行比较时,我的计算结果已关闭。提前打了你这么多,我的数学也很糟糕,所以我提前道歉。
以下是我的应用给我的结果:
http://www.tiikoni.com/tis/view/?id=8bd04d4
以下是BMI网站NIH的结果
http://www.tiikoni.com/tis/view/?id=86d4458
BMIFRAG.java
public class BmiFrag extends Fragment implements View.OnClickListener
{
Button BmiButton;
public static EditText heightFT;
public static EditText heightIn;
public static EditText weightIn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myView = inflater.inflate(R.layout.fragment_bmi, container,
false);
BmiButton = (Button) myView.findViewById(R.id.CalculateBmi);
BmiButton.setOnClickListener(this);
return myView;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.CalculateBmi:
weightIn = (EditText)
getActivity().findViewById(R.id.ETtweight);
heightIn = (EditText)
getActivity().findViewById(R.id.ETHeightIn);
heightFT = (EditText)
getActivity().findViewById(R.id.ETHeightFT);
final TextView tv4 = (TextView)
getActivity().findViewById(R.id.TFDisplayBmi);
String getWeightIN = weightIn.getText().toString();
String getHeightIN = heightIn.getText().toString();
String getHeightFT = heightFT.getText().toString();
if (TextUtils.isEmpty(getWeightIN)) {
weightIn.setError("Please enter your weight");
weightIn.requestFocus();
return;
}
else if (TextUtils.isEmpty(getHeightIN)) {
heightIn.setError("Please enter your height in Inches");
heightIn.requestFocus();
return;
}
else if (TextUtils.isEmpty(getHeightFT)) {
heightFT.setError("Please enter your height in Feet");
heightFT.requestFocus();
return;
}
else {
float weight = Float.parseFloat(getWeightIN );
float heightIN = Float.parseFloat(getHeightIN) ;
float heightFT = Float.parseFloat(getHeightFT) ;
float bmiValue = calculateBMI(weight,heightIN,heightFT);
String bmiInterpretation = interpretBMI(bmiValue);
tv4.setText(String.valueOf(bmiValue + "-" +
bmiInterpretation));
}
break;
}
}
private float calculateBMI(float weight, float heightIN, float v) {
float bmi= (float) (weight/ (heightIN*v)*4.88);
float total= Math.round(bmi);
return total;
}
private String interpretBMI(float bmiValue) {
if (bmiValue < 16) {
return "Severely underweight";
} else if (bmiValue < 18.5) {
return "Underweight";
} else if (bmiValue < 25) {
return "Normal";
} else if (bmiValue < 30) {
return "Overweight";
} else {
return "Obese";
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onDetach() {
super.onDetach();
}
答案 0 :(得分:2)
您不能使用相同的公式。试试这个:
float bmi = weight * 703f / (float)Math.pow(heightIN+12f*v,2);
上面的公式可以找到here。
我希望它有所帮助。