title: onTextChanged event doesn't work in Android
body: <p>I have an <code>EditBox</code> and a <code>TextView</code> in an application.
  I want the TextView to convert numbers that I type into the EditBox to words as I'm typing ( <code>onTextChanged()</code> ) and show it.
  I made the class for converting numbers to words and it works correctly.
  I search for <code>onTextChanged</code> event and I found how to use it but I faced a problem.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>ed.addTextChangedListener(new TextWatcher() {
      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
  
      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count) {
          try {
  
              String num = ed.getText().toString();
              String str = num.replace(",", "");
              double x = Double.parseDouble(str);
              String text = NumberFormat.getIntegerInstance(Locale.US).format(x);
  
              ed.setText(text);
  
              /*if (ed.length() != 0)
              {
                  String numtoalph = NumToAlph.convert(x);
                  tv.setText( numtoalph + tv.getText().toString());
              }*/
  
              NumToAlph numToAlph = new NumToAlph();
              String alph = NumToAlph.Convert(text, x);
              tv.setText(alph + " ریال");
  
          }
          catch (Exception ex)
          {
              tv.setText(ex.toString());
          }
  
  
          @Override
          public void afterTextChanged(Editable s) {}
  
  });
  </code></pre>
  
  <p><strong>*NumToAlph is the class</strong></p>
  
  <p>When I installed it on my phone and tried to type as I pressed the first button the app froze and after a minute I got a notification which said that </p>
  
  <blockquote>
    <p>this app is using too much CPU</p>
  </blockquote>
  
  <p>I tested the code, I mean this </p>
  
  <pre><code>try {
  
      String num = ed.getText().toString();
      String str = num.replace(",", "");
      double x = Double.parseDouble(str);
      String text = NumberFormat.getIntegerInstance(Locale.US).format(x);
  
      ed.setText(text);
      /*
      if (ed.length() != 0)
      {
          String numtoalph = NumToAlph.convert(x);
          tv.setText( numtoalph + tv.getText().toString());
      }
      */
  
      NumToAlph numToAlph = new NumToAlph();
      String alph = NumToAlph.Convert(text, x);
      tv.setText(alph + " ریال");
  }
  catch (Exception ex)
  {
      tv.setText(ex.toString());
  }
  </code></pre>
  
  <p>in a button click event and it worked fast and correctly.
  Does any one have an idea about this problem?</p>
  
  <p>I have programmed this app for windows in C# before, and used this for textChanged event with no problems: </p>
  
  <pre><code>decimal Number;
  if (decimal.TryParse(textBox1.Text, out Number))
  {
      textBox1.Text = string.Format("{0:N0}", Number);
      textBox1.SelectionStart = textBox1.Text.Length;
  }
  
  try
  {
      NumToAlph dd = new NumToAlph();
      string x = textBox1.Text.Replace(",", "").ToString();
      textBox2.Text = dd.num2str(x) + " ریال";
  }
  catch (Exception ex)
  {
      MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
  </code></pre>