title: Making parsing easier in android EditText
body: <p>I have an app with a couple of EditTexts. The user leaves on empty and the program calculates the empty variable. This is the onClickListener for the button that initiates it all. I was looking to get all the parsing done before the switch so that I only need to parse ALL entries once and then have a 0 put in for the empty one as this would give an error.</p>
  
  <p>How can I streamline this code?</p>
  
  <pre><code>public void buttonCalc() {
      calc.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
              pv = (EditText) getActivity().findViewById(R.id.pv_pv);
              fv = (EditText) getActivity().findViewById(R.id.pv_fv);
              r = (EditText) getActivity().findViewById(R.id.pv_r);
              n = (EditText) getActivity().findViewById(R.id.pv_n);
              t = (EditText) getActivity().findViewById(R.id.pv_t);
              answer = (TextView) getActivity().findViewById(R.id.pv_answer);
              //check for fields and choice
              if (pv.getText().toString().equals("")) {emptyfields++;choice = 1;}
              if (fv.getText().toString().equals("")) {emptyfields++;choice = 2;}
              if (r.getText().toString().equals("")) {emptyfields++;choice = 3;}
              if (n.getText().toString().equals("")) {emptyfields++;choice = 4;}
              if (t.getText().toString().equals("")) {emptyfields++;choice = 5;}
              if (emptyfields &gt; 1) {MiscMethods.ErrorToast(1);}
              else{
                  emptyfields--;
                  try {
  
                  } catch (Exception e) {
                  }
                  switch (choice) {
                  case 1:// pv
                      double fv1 = Double.parseDouble(fv.getText().toString());
                      double r1 = Double.parseDouble(r.getText().toString());
                      double n1 = Double.parseDouble(n.getText().toString());
                      double t1 = Double.parseDouble(t.getText().toString());
                      double result1 = fv1/(Math.pow(1+(r1/n1),n1*t1));
                      result1 = MiscMethods.rounder(result1, 2);
                      answer.setText(answer_pv + result1);
                      break;
                  case 2:// fv
                      double pv2 = Double.parseDouble(pv.getText().toString());
                      double r2 = Double.parseDouble(r.getText().toString());
                      double n2 = Double.parseDouble(n.getText().toString());
                      double t2 = Double.parseDouble(t.getText().toString());
                      double result2 = pv2*(Math.pow(1 + (r2 / n2), n2 * t2));
                      result2 = MiscMethods.rounder(result2, 2);
                      answer.setText(answer_fv + result2);
                      break;
                  case 3:// r
                      double pv3 = Double.parseDouble(pv.getText().toString());
                      double fv3 = Double.parseDouble(fv.getText().toString());
                      double n3 = Double.parseDouble(n.getText().toString());
                      double t3 = Double.parseDouble(t.getText().toString());
                      double result3 = ((Math.pow(fv3 / pv3, (1 / (n3 * t3)))) - 1)* n3;
                      result3 = MiscMethods.rounder(result3, 4);
                      answer.setText(answer_r +" "+ result3 + " / " + (result3*100)+"%");
                      break;
                  case 4:// n
                      MiscMethods.ErrorToast(2);
                      break;
                  case 5:// t
                      double pv5 = Double.parseDouble(pv.getText().toString());
                      double fv5 = Double.parseDouble(fv.getText().toString());
                      double n5 = Double.parseDouble(n.getText().toString());
                      double r5 = Double.parseDouble(r.getText().toString());
                      double result5 = (Math.log((fv5 / pv5))) / ((Math.log((1 + (r5 / n5)))) * n5);
                      result5 = MiscMethods.rounder(result5, 2);
                      answer.setText(answer_t +" "+ result5);
                      break;
                  default:
                      MiscMethods.ErrorToast(3);
                      break;
                  }// switch ends
              }// else ends
  
          }
  
      });
  }
  </code></pre>