Note that there are some explanatory texts on larger screens.

plurals
  1. POonTextChanged when I delete the value totaly
    primarykey
    data
    text
    <p>I'm trying to build a tip calc. This is part of my code:</p> <pre><code>public void onTextChanged(CharSequence s, int start, int before, int count) { double billAmount = Double.parseDouble(s.toString()); tip10EditText.setText("" + billAmount * .1); tip15EditText.setText("" + billAmount * .15); tip20EditText.setText("" + billAmount * .2); total10EditText.setText("" + (billAmount + billAmount * 0.1)); total15EditText.setText("" + (billAmount + billAmount * 0.15)); total20EditText.setText("" + (billAmount + billAmount * 0.2)); } </code></pre> <p>The problem is, when I delete everything from the bill edit text, the app crashes.. My friend found some way to deal with it. Here is he's code:</p> <pre><code>public void onTextChanged(CharSequence s, int start, int before, int count) { if (!s.toString().equals("")) { bill = Double.parseDouble(s.toString()); tip10EditText.setText((bill / 10) + ""); total10EditText.setText((bill + (bill / 10)) + ""); // the String.format("%.2f", is to SHORTEN the tail of the double to 2 digits tip15EditText.setText(String.format("%.2f", (bill / 6.6666) )); total15EditText.setText(String.format("%.2f",(bill + (bill / 6.6666)) )); tip20EditText.setText(String.format("%.2f", (bill / 5) )); total20EditText.setText(String.format("%.2f",(bill + (bill / 5)) )); // to handle the seekBar changing according to the bill double billCu = Double.parseDouble(billEditText.getText().toString()); // total20EditText.setText(String.format("%.2f",(tipOf )); double progressPer=Double.parseDouble(customTipTextView.getText().toString()); double tipOf = (billCu/100)*progressPer; tipCustomEditText.setText(String.format("%.2f",(tipOf ))); totalCustomEditText.setText(String.format("%.2f",((billCu+tipOf) ))); } else { tip10EditText.setText( ""); total10EditText.setText( ""); tip15EditText.setText( ""); total15EditText.setText( ""); tip20EditText.setText( ""); total20EditText.setText( ""); tipCustomEditText.setText(""); totalCustomEditText.setText(""); } } </code></pre> <p>Is there a better way to deal with this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload