Search Unity

Detect Submit on Android

Discussion in 'UGUI & TextMesh Pro' started by jebi, Aug 30, 2014.

  1. jebi

    jebi

    Joined:
    Jul 7, 2013
    Posts:
    6
    Hi guys. I'm trying to detect submit on inputfield. I found this code;

    Code (JavaScript):
    1. import UnityEngine.UI;
    2.  
    3. public var myInput : InputField;
    4.  
    5. function Start(){
    6.     myInput.onSubmit.AddListener(myInputSubmit);
    7. }
    8.  
    9. function myInputSubmit(){
    10.     Debug.Log("test");
    11. }
    It's work on desktop, but not works on Android. How can handle this?
     
  2. crag

    crag

    Joined:
    Dec 13, 2013
    Posts:
    145
    Not sure what you are looking for but you could leverage:

    Code (JavaScript):
    1. if (GUI.changed) {
    2.     Debug.Log("Text field has changed.");
    3.     // do something
    4. }
     
  3. jebi

    jebi

    Joined:
    Jul 7, 2013
    Posts:
    6
    I'm looking for this buttons click event;

    Untitled-1.jpg

    Or might be keyboard close event, if is exists :) Thank you for reply :)
     
  4. crag

    crag

    Joined:
    Dec 13, 2013
    Posts:
    145
  5. jebi

    jebi

    Joined:
    Jul 7, 2013
    Posts:
    6
    Thank you man, you are awesome! :D
    Here is my code; I used Text instead of InputField.
    You must be call openKeyboard function on myText clicked.
    Code (JavaScript):
    1. import UnityEngine.UI;
    2.  
    3. public var myText : Text; // this your input field
    4.  
    5. private var Keyboard : TouchScreenKeyboard;
    6. private var isKeyboardOpen : boolean;
    7. private var KeyboardText : String = ""; // default text
    8.  
    9. function openKeyboard(){
    10.     Keyboard = TouchScreenKeyboard.Open(KeyboardString, TouchScreenKeyboardType.Default);
    11.     isKeyboardOpen = true;
    12. }
    13.  
    14. function Update(){
    15.     if(isKeyboardOpen && Keyboard){
    16.            if (Keyboard.done){
    17.             //keyboard submitted
    18.             isKeyboardOpen = false;
    19.             myText.text = KeyboardText;
    20.             //do your staff
    21.            }
    22.         if(Keyboard)
    23.             KeyboardText = Keyboard.text;
    24.    }
    25. }
     
    svlewis likes this.