Reputation: 121
I have a program I'm upgrading from Android 7.1.1 to now 8.1. Most things have gone incredibly smoothly, but I have hit a snag on one thing.
I have a postal code entry using an EditText. This entry begins initially with an InputType of ClassText and as the user enters their characters, I am swapping back and forth from ClassText to ClassNumber to get a resulting format such as: "M1N2J8"
On 7.1.1 this works, no problems. However, the behavior seems to have changed in 8.1. When I enter "M" and then "1", I have no problem, but after I have changed it back to ClassText to enter the "N" it wipes out the "1" and leaves me with "MN"
I would greatly appreciate any insights anyone may be able to offer on how I can get around this. Worst case scenario, I'll simply enable an alphanumeric keyboard and handle the restricting the characters myself, but my client greatly prefers to have the keyboards swap between text and number entry, so that's my goal right now.
Thanks!
if (txt.SelectionStart == 0 || txt.SelectionStart == 2 || txt.SelectionStart == 4)
{
txt.InputType = InputTypes.ClassText | InputTypes.TextFlagCapCharacters;
txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength), new AlphaInputFilter() });
}
else if (txt.SelectionStart == 1 || txt.SelectionStart == 3 || txt.SelectionStart == 5)
{
txt.InputType = InputTypes.ClassNumber;
txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength), new NumberInputFilter() });
}
Upvotes: 0
Views: 148
Reputation: 1651
You don't need to use the second InputFilter, Your final output is alphanumeric and won't fit on any of them
if (txt.SelectionStart == 0 || txt.SelectionStart == 2 || txt.SelectionStart == 4)
{
txt.InputType = InputTypes.ClassText | InputTypes.TextFlagCapCharacters;
txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength) });
}
else if (txt.SelectionStart == 1 || txt.SelectionStart == 3 || txt.SelectionStart == 5)
{
txt.InputType = InputTypes.ClassNumber;
txt.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(maxLength) });
}
Upvotes: 1