roim
roim

Reputation: 4930

Android SoftKeyboard on SurfaceView

I'm trying to use the Soft Keyboard on a SurfaceView in my game. Problem is I can't handle onKey events.

I've tried implementing an OnKeyListener on my view, and overriding:

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    Log.w("Key", "Key Pressed");
    return true;
}

But I don't receive any key events.

Using

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.w("Key", "Key Pressed");
    return true;
}

Doesn't work either.

Upvotes: 0

Views: 652

Answers (1)

roim
roim

Reputation: 4930

Turned out I had to specify the following on the view constructor hook:

setFocusable(true);
setFocusableInTouchMode(true);

since input events are only sent to the focused view.

Upvotes: 1

Related Questions