Create Phone Mask for Edittext

Asked

Viewed 3,204 times

2

I’m trying to create a mask for my phone field, I saw some forums and tried the code below, but it is putting another pattern... I need to put in the pattern.

EditText inputField = (EditText) FindViewById(Resource.Id.editMensagemTelefone);
inputField.AddTextChangedListener(new PhoneNumberFormattingTextWatcher());

1 answer

2


As of API 21, builder that receives a string containing a country code that will be used by PhoneNumberFormattingTextWatcher.

The builder without parameters invokes Locale.getDefault().getCountry() to get which country code to use for the formatter.

Also consider using the most idiomatic way of Xamarin to get your View, which is to use the generic method FindViewById. The result would be this:

var inputField = FindViewById<EditText>(Resource.Id.editMensagemTelefone);
inputField.AddTextChangedListener(new PhoneNumberFormattingTextWatcher("BR"));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.