jlim
jlim

Reputation: 811

Android onKey w/ virtual keyboard

I am catching keyboard events/presses using the onKey method:

public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
    //do something
    return false;
}

This fires off just fine for physical keyboard presses but it does not fire on virtual keyboard presses. Is there an event handler to handle virtual keyboard presses?

Upvotes: 2

Views: 2914

Answers (3)

James
James

Reputation: 841

If it's an EditText, see if you can use a TextChangedListener instead.

myEditText.addTextChangedListener(new TextWatcher(){
        public void afterTextChanged(Editable s) {}
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //do stuff
        }

    });

Upvotes: 8

jlim
jlim

Reputation: 811

myEditText.addTextChangedListener(new TextWatcher(){
        public void afterTextChanged(Editable s) {}
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //do stuff
        }

    });

Upvotes: 1

user249290
user249290

Reputation: 116

Virtual keypresses are delivered directly to the selected view, they don't propagate through parent views like hardware keypresses. Are you overriding onKey on something other than the EditText/List/Whatever that's getting keypresses? (the thing you click on to get the virtual keyboard)

Upvotes: 1

Related Questions