Reputation: 811
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
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
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
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