title: EditText custom string formatting
body: <p>I searched every question similar to my problem but didn't get it working. My problem is this:</p>
  
  <p>I want to format a string in <code>EditText</code> while typing. The format is this (<strong>it's always a 19 digit number</strong>):</p>
  
  <p><strong>012345 01 0123456789 0</strong></p>
  
  <p>As you can see I want to add spaces when they are needed while the user is typing. I know that I have to use the <code>TextWatcher</code> but everything I do I don't get what i want.</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Here is the code of my last try:</p>
  
  <pre><code>        @Override
          public void afterTextChanged(Editable s) {
             if(s.length() == 7 || s.length() == 10 || s.length() == 21){
                  editText.removeTextChangedListener(this);
                  String newValue;
                  newValue= s.insert((s.length()-1), " ").toString();
                  //Log.d("AFTER",newValue);
                  editText.setText(newValue);
                  editText.setSelection(newValue.length());
                  editText.addTextChangedListener(this);
              }
          }
  </code></pre>