0

I´m facing some troubles, I made an easy App where the user needs to input a time into an input field. The time have to be in a HH:mm format, I already figured out how to limit the characters, but I´m now wondering if it´s possible that the inputfield sets the colon itself. So that the user types in the hours then the colon appears and then he types the minutes. Is this possible? And how can I set it up like this.

Thanks in advance and friendly regards

C00K13M4N
  • 25
  • 1
  • 9
  • Use TextWatcher on your EditText. see [this](https://stackoverflow.com/questions/8543449/how-to-use-the-textwatcher-class-in-android) for more understanding – Molly Jan 21 '19 at 11:14
  • Great Idea, but I fail finding the Textwatch enviroment in Unity3D – C00K13M4N Jan 21 '19 at 11:28

1 Answers1

0

Thanks for the initial idea,

Chandrani Chatterjee

But as I didn't find the TextWatcher Utility in Unity3D i did it in an other maybe easier Way. My Code is posted below, maybe someone can use it in advance.

public void OnValueChanged(string input) 
{

    if (input.Length == 2)
    {
        InputField.text = input+":";
        InputField.caretPosition = 3;
    }

}

To start the "Listening" I use the following Method.

void Awake()
{
    InputField.onValueChanged.AddListener(OnValueChanged);
}

Thanks to everyone, once again you Guys did help me.

Best regards Tobi

C00K13M4N
  • 25
  • 1
  • 9