Reputation: 589
I would like to make a EditText field with format like this: 0000 AA.
Is it possible to make number keyboard appear at first 4 numbers then automatically make a space and then make normal keyboard appear?
How can I do that with C#?
Somebody an idea?
Upvotes: 0
Views: 2319
Reputation: 1076
This should do the trick:
EditText zipcode = FindViewById<EditText>(Resource.Id.zipcode);
zipcode.InputType = Android.Text.InputTypes.ClassNumber;
bool numberMode = true;
zipcode.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
if(zipcode.Text.Length == 4){
if(numberMode){
numberMode = false;
zipcode.Text = zipcode.Text + " ";
zipcode.SetSelection(zipcode.Text.Length);
}
}
if(zipcode.Text.Length > 4){
numberMode = false;
zipcode.InputType = Android.Text.InputTypes.ClassText;
}
if(zipcode.Text.Length <= 4){
numberMode = true;
zipcode.InputType = Android.Text.InputTypes.ClassNumber;
}
};
Upvotes: 2