Search code examples
androidnativescriptangular2-nativescript

Nativescript - Keep keyboard open when TextField returned on Android


How can I keep the keyboard open after the user tap on the "Return" key on the soft keyboard? I'm calling the focus method on "returnPress" event, which works fine on IOS but not on android:

text() {
    let textFieldElement = <TextField>this.textField.nativeElement;
    textFieldElement.focus();
}

Solution

  • So turns out I need to overrde "onEditorAction" method on the "OnEditorActionListener" like this:

        let tv = <TextField>this.textField.nativeElement;
    
        if (tv.android) {
            tv.android.setOnEditorActionListener(new android.widget.TextView.OnEditorActionListener({
                onEditorAction: function (callbackType, result) {
                    if (result == android.view.inputmethod.EditorInfo.IME_ACTION_DONE) {
                            // do whatever you want when user presses return
                    }
                    return true;
                }
            }));
        }