Code example for PhoneNumberFormattingTextWatcher

Methods: afterTextChangedbeforeTextChanged

0
 
public class PhoneNumberWatcherTest extends TestCase {
    @SmallTest 
    public void testHyphenation() throws Exception { 
        SpannableStringBuilder number = new SpannableStringBuilder();
        TextWatcher tw = new PhoneNumberFormattingTextWatcher();
        number.append("555-1212");
        // Move the cursor to the left edge 
        Selection.setSelection(number, 0);
        tw.beforeTextChanged(number, 0, 0, 1);
        // Insert an 8 at the beginning 
        number.insert(0, "8");
        tw.afterTextChanged(number);
        assertEquals("855-512-12", number.toString());
    } 
     
    @SmallTest 
    public void testHyphenDeletion() throws Exception { 
        SpannableStringBuilder number = new SpannableStringBuilder();
        TextWatcher tw = new PhoneNumberFormattingTextWatcher();
Contextual code suggestions in your IDE  Get Codota for Java