/* Bryan BMI Calculator */ package bryan.bmicalculator; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class DisplayFragment extends Fragment { private TextView tv_Name, tv_BMIValue, tv_BMIInt; public DisplayFragment() {} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_display, container, false); tv_Name = v.findViewById(R.id.tv_NameOutput); tv_BMIValue = v.findViewById(R.id.tv_BMIValueOuput); tv_BMIInt = v.findViewById(R.id.tv_BMIIntOutput); return v; } /** * Sets the users name * @param name */ public void setUsersName(String name) { tv_Name.setText(name); } /** * Sets the users BMI calculated value and human readable interpretation * @param value */ public void setBMIValue(Double value) { String interpretation; if (value < 18.5) { interpretation = getString(R.string.bmi_under); } else if (value >= 18.5 && value <= 24.9) { interpretation = getString(R.string.bmi_normal); } else if (value >= 25.0 && value <= 29.9) { interpretation = getString(R.string.bmi_over); } else { interpretation = getString(R.string.bmi_obese); } tv_BMIInt.setText(interpretation); tv_BMIValue.setText(String.format("%.2f", value)); } }