title: How do I implement specific phone number formatting with an EditText and ICS?
body: <p>My app requires that phone numbers be formatted like xxx-xxx-xxxx.  The code below worked prior to ICS, but ICS devices completely ignore the formatting text watcher.  Why does it ignore the formatter and how can I get ICS to follow the expected format?</p>
  
  <p>I'm setting up the filter and text listener as:</p>
  
  <pre><code>final EditText phoneNumber = (EditText) findViewById(R.id.phoneNumber);
  phoneNumber.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
  phoneNumber.setFilters(new InputFilter[] { new PhoneNumberFilter(), new InputFilter.LengthFilter(12) });
  </code></pre>
  
  <p>Code for the PhoneNumberFilter:</p>
  
  <pre><code>import android.text.InputType;
  import android.text.Spanned;
  import android.text.method.NumberKeyListener;
  
  public class PhoneNumberFilter extends NumberKeyListener {
  
      @Override
      public int getInputType() {
          return InputType.TYPE_CLASS_PHONE;
      }
  
      @Override
      protected char[] getAcceptedChars() {
          return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' };
      }
  
      @Override
      public CharSequence filter(CharSequence source, int start, int end,
              Spanned dest, int dstart, int dend) {
  
          // Don't let phone numbers start with 1
          if (dstart == 0 &amp;&amp; source.equals("1")) 
              return "";
  
          return super.filter(source, start, end, dest, dstart, dend);
      }
  }
  </code></pre>