Code example for PhoneNumberFormattingTextWatcher

0
            mTextView = textView;
        } 
 
        @Override 
        protected PhoneNumberFormattingTextWatcher doInBackground(Void... params) {
            return new PhoneNumberFormattingTextWatcher(mCountryCode);
        } 
 
        @Override 
        protected void onPostExecute(PhoneNumberFormattingTextWatcher watcher) {
            if (watcher == null || isCancelled()) {
                return; // May happen if we cancel the task. 
            } 
            // Setting a text changed listener is safe even after the view is detached. 
            mTextView.addTextChangedListener(watcher);
 
            // Note changes the user made before onPostExecute() will not be formatted, but 
            // once they type the next letter we format the entire text, so it's not a big deal. 
            // (And loading PhoneNumberFormattingTextWatcher is usually fast enough.) 
            // We could use watcher.afterTextChanged(mTextView.getEditableText()) to force format