Android TextWatcher - top ranked examples from Open Source projects

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

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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:afterTextChanged, beforeTextChanged
    } 
     
    @SmallTest 
    public void testHyphenDeletion() throws Exception { 
        SpannableStringBuilder number = new SpannableStringBuilder();
        TextWatcher tw = new PhoneNumberFormattingTextWatcher();
        number.append("555-1212");
        // Move the cursor to after the hyphen 
        Selection.setSelection(number, 4);
        // Delete the hyphen 
        tw.beforeTextChanged(number, 3, 1, 0);
        number.delete(3, 4);
        tw.afterTextChanged(number);
        // Make sure that it deleted the character before the hyphen  
        assertEquals("551-212", number.toString());
         
        // Make sure it deals with left edge boundary case 
        number.insert(0, "-");
        Selection.setSelection(number, 1);
        tw.beforeTextChanged(number, 0, 1, 0);

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:onTextChanged

Related Android TextWatcher Questions & Answers:

Other Android TextWatcher Examples

46:	         * Enabling Search Filter
47:	         * */
48:	        inputSearch.addTextChangedListener(new TextWatcher() {
49:				
50:				@Override

Read More

See Code Examples for Android TextWatcher Methods: