2

I have a WebView in my Android Application that is giving me a problem. At first was not handling the keyDown event correctly for the arrow keys, and I had to catch the keyDown and use Javascript like this to process them correctly:

    @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.v(TAG, "KeyCode: " + keyCode + "    KeyEvent: " + event);
    switch(keyCode) {
    case 19: /* Up */
        this.loadUrl("javascript:editor.setCursor(editor.getCursor().line - 1, editor.getCursor().ch);");
    case 20: /* Down */
        this.loadUrl("javascript:editor.setCursor(editor.getCursor().line + 1, editor.getCursor().ch);");
    case 21: /* Left */
        this.loadUrl("javascript:editor.setCursor(editor.getCursor().line, editor.getCursor().ch - 1);");
    case 22: /* Right */
        this.loadUrl("javascript:editor.setCursor(editor.getCursor().line, editor.getCursor().ch + 1);");
    }
    return super.onKeyDown(keyCode, event);
}

But now I am getting an issue that every time I use one of the arrow keys the soft keyboard is hiding.

I found one other question here on Stackoverflow that seems to be the exact same issue, but nobody answered him:

Prevent Buttons From Hiding Soft Keyboard On Android

Is there some way I can prevent the softkeyboard from hiding on me?

Community
  • 1
  • 1
Shane Grant
  • 2,484
  • 4
  • 26
  • 32

1 Answers1

0

Because loadUrl/loadData/loadDataWithBaseUrl internally hides soft keyboeard. You should not send javascript events until user has typed everything he wants. If it is appropriate, handle events via javascript.

I4004
  • 145
  • 2
  • 11