title: Set empty edittext value to zero
body: <p>I have created a simple program to try to figure out how to do this. it has two edit text fields (input type number decimal), a text view and a button. I want the sum of the two input fields to be displayed in the text view when the user hits the button. can someone tell me how to set the value of one edit text field to zero if the user left it blank? I have tried many ways but nothing worked.
  Edit: i want to achieve this while keeping the hint of edit text as before (without changing the value to zero like " setText("0"); ".</p>
  
  <p>here's my java code (tell me what to add)</p>
  
  <pre><code>package com.example.android.testedittexttozero;
  
  import...
  
  public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  
  public void calculate(View v) {   //the button
      final EditText number1 = (EditText) findViewById(R.id.numberFirst);
      EditText number2 = (EditText) findViewById(R.id.numberSecond);
      TextView total = (TextView) findViewById(R.id.totalTV);
  
      try {
          int a = Integer.parseInt(number1.getText().toString());
          int b = Integer.parseInt(number2.getText().toString());
          int sum = a + b;
  
          total.setText("" + sum);
  
      } catch (Exception e) {
          Toast.makeText(getApplicationContext(), "One or more field is empty", Toast.LENGTH_LONG).show();
  
  
      }
  }
  }
  </code></pre>