TextWatcher onTextChanged - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TextWatcher onTextChanged method.

This code example shows how to use the following methods:afterTextChanged, beforeTextChanged, onTextChanged
        final String expected1 = "(650) 123 4";
        TextWatcher textWatcher = getTextWatcher();
 
        // Append space 
        SpannableStringBuilder number = new SpannableStringBuilder(init);
        textWatcher.beforeTextChanged(number, 9, 0, 2);
        number.insert(9, " 4"); // (650) 123 4
        Selection.setSelection(number, number.length()); // make the cursor at right of 4
        textWatcher.onTextChanged(number, 9, 0, 2);
        textWatcher.afterTextChanged(number);
        assertEquals(expected1, number.toString());
        // the cursor should still at the right of '4' 
        assertEquals(expected1.length(), Selection.getSelectionEnd(number));
 
        // Clear the current string, and start formatting again. 
        int len = number.length();
        textWatcher.beforeTextChanged(number, 0, len, 0);
        number.delete(0, len);
        textWatcher.onTextChanged(number, 0, len, 0);
        textWatcher.afterTextChanged(number);

7
CodeRank
This code example shows how to use the following methods:afterTextChanged, beforeTextChanged, onTextChanged
        final String expected1 = "(650) 123 4";
        TextWatcher textWatcher = getTextWatcher();
 
        // Append space 
        SpannableStringBuilder number = new SpannableStringBuilder(init);
        textWatcher.beforeTextChanged(number, 9, 0, 2);
        number.insert(9, " 4"); // (650) 123 4
        Selection.setSelection(number, number.length()); // make the cursor at right of 4
        textWatcher.onTextChanged(number, 9, 0, 2);
        textWatcher.afterTextChanged(number);
        assertEquals(expected1, number.toString());
        // the cursor should still at the right of '4' 
        assertEquals(expected1.length(), Selection.getSelectionEnd(number));
 
        // Clear the current string, and start formatting again. 
        int len = number.length();
        textWatcher.beforeTextChanged(number, 0, len, 0);
        number.delete(0, len);
        textWatcher.onTextChanged(number, 0, len, 0);
        textWatcher.afterTextChanged(number);

7
CodeRank
This code example shows how to use the following methods:onTextChanged
onTextChanged Method Overview
This method is called to notify you that, within s, the count characters beginning at start have just replaced old text that had length before.
See Code Examples for other Android TextWatcher Methods: