2D Toolkit Forum
2D Toolkit => Support => Topic started by: Jix on August 28, 2014, 04:36:13 am
-
Hello, I wrote a function to let tk2dUITextInput take only numbers from the users because this important feature isn't included in 2DToolkit. I want it to show only numbers so I made it that when the text input changes it will call this function
void Check_UI_Input(tk2dUITextInput input)
{
string txt = "";
for (int i = 0; i < input.Text.Length; i++)
{
if (char.IsDigit(input.Text[i]))
txt += input.Text[i];
}
if (txt.Length > 0)
{
int number = int.Parse(txt);
input.Text = number >= 0 ? number.ToString() : "0";
}
else
input.Text = "";
}
It works well in the Editor but when I deployed it on Android everything got messed up
-
On android it uses the built in text input system, you'd probably need to modify this line -
keyboard = TouchScreenKeyboard.Open(text, TouchScreenKeyboardType.Default, false, false, false, false);
to
keyboard = TouchScreenKeyboard.Open(text, TouchScreenKeyboardType.NumberPad, false, false, false, false);
-
Thanks, does this problem also appear on iOS?
-
No idea. They behave differently on all platforms supporting the touchscreen keyboard, but I cant remember how each platform works. You're best off adding the option I mentioned so you're filtering stuff off at the keyboard itself.
-
Ok, thanks a lot :-)