Android EditText InputFilter
<p>How to delete two character at once with the filter?</p>

<p>I am trying to apply a simple filter to an EditText.<br>
It must work as follows:<br>
(want to receive format: 1234 5678....)   </p>

<p>===> EDITED: First part works well.</p>

<p>1) when there are 4 digits in EditText and I am entering the 5-th digit -<br>
first must appear a space and then this digit.<br>
 2) And I need a reverse for this (during characters deletion) -<br>
the space must be deleted with the 5-th digit.</p>

<p>What is wrong with my code?  </p>

<pre><code>editText.setFilters(new InputFilter[]{new DigitsKeyListener(Boolean.FALSE, Boolean.TRUE) {

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

        //  any chars except backspace
        if (!source.equals("")) {
            if (dest.length() == 4) {
                // here I must add a space and then the source
                // ===&gt; EDITED:
                return " " + source;
                // return super.filter(" " + source, start, end + 1, dest, dstart, dend + 1);
            } // backspace entered
        } else {
            if (dest.length() == 6) {
                // here I must delete the 6-th character 
                // and the space before
                return super.filter(source, 0, 0, dest, 5, 6);
            }
        }

        return null;
    }
}});
</code></pre>