/* Bryan BMI Calculator */ package bryan.bmicalculator; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.TextView; public class InputFragment extends Fragment { public InputFragment() {} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { EditText tb_Name, tb_HeightFeet, tb_HeightInches, tb_Weight; // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_input, container, false); // Get the edit texts tb_Name = v.findViewById(R.id.tb_Name); tb_HeightFeet = v.findViewById(R.id.tb_HeightFeet); tb_HeightInches = v.findViewById(R.id.tb_HeightInches); tb_Weight = v.findViewById(R.id.tb_Weight); // Set an EH for the submit button v.findViewById(R.id.btn_Submit).setOnClickListener(view -> { Double bmi; // Get the inches from inches and feet Integer inches = Integer.parseInt(tb_HeightInches.getText().toString()); Double weight = Double.parseDouble(tb_Weight.getText().toString()); // convert feet to inches inches += Integer.parseInt(tb_HeightFeet.getText().toString()) * 12; // Calculate the bmi bmi = (weight * 703) / Math.pow(inches, 2); // Create a fragment manager FragmentManager fm = getFragmentManager(); // Create an instance of output fragment DisplayFragment df = (DisplayFragment) fm.findFragmentById(R.id.fg_Output); // Set their name df.setUsersName(tb_Name.getText().toString()); // Set the BMI df.setBMIValue(bmi); }); return v; } }