Hello Guest

Author Topic: How do I adjust tk2dUITextInput to accept numbers only?  (Read 4909 times)

Jix

  • Newbie
  • *
  • Posts: 10
    • View Profile
How do I adjust tk2dUITextInput to accept numbers only?
« 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
Code: [Select]
    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
« Last Edit: August 28, 2014, 04:39:44 am by Jix »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I adjust tk2dUITextInput to accept numbers only?
« Reply #1 on: August 28, 2014, 11:50:49 am »
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);

Jix

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How do I adjust tk2dUITextInput to accept numbers only?
« Reply #2 on: August 31, 2014, 10:49:32 pm »
Thanks, does this problem also appear on iOS?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I adjust tk2dUITextInput to accept numbers only?
« Reply #3 on: September 01, 2014, 11:17:52 am »
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.

Jix

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: How do I adjust tk2dUITextInput to accept numbers only?
« Reply #4 on: September 04, 2014, 11:40:40 pm »
Ok, thanks a lot :-)