Create Phone Mask for EditText

2

I'm trying to create a masquerade for my phone field, I saw some forums and tried the code below, but it's putting another pattern ... I need to put it in the default br.

EditText inputField = (EditText) FindViewById(Resource.Id.editMensagemTelefone);
inputField.AddTextChangedListener(new PhoneNumberFormattingTextWatcher());
    
asked by anonymous 24.05.2015 / 22:03

1 answer

2

API 21 has added a constructor > that receives a string containing a country code that will be used by PhoneNumberFormattingTextWatcher .

The non-parametric constructor invokes Locale.getDefault().getCountry() to get which country code to use for the formatter.

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

var inputField = FindViewById<EditText>(Resource.Id.editMensagemTelefone);
inputField.AddTextChangedListener(new PhoneNumberFormattingTextWatcher("BR"));
    
25.08.2015 / 20:42