CORRECTION:
For a while, I used a generic onKeyListener. I soon found that my code was being called twice. Once with the key down and once with key up. I now use the following listener and only call the code once.
"if (event.getAction() == KeyEvent.ACTION_UP)"
is the key.
OnKeyListener keyListener = new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP) {
//do something here
}
return false;
}
};
I found that onKeyUp()
is called automatically for every control in the Activity. If this is what you want, add it to the Activity just like you add the onCreate()
Example:
public boolean onKeyUp(int keyCode, KeyEvent event) {
//do something here
return false;
};
I know this is a old question, but maybe this will help others with the same issue.