I've implemented dispatchKeyEvent in my activity to listen to the Enter key being pressed. The problem is that when i click enter,it calls my method twice ? How can i fix this ? Thanks,have a nice day !
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
enter();
return true;
}
return super.dispatchKeyEvent(e);
};
Fixed it,done this :
At first i was doing ACTION_DOWN
but that was triggering an older problem of mine.
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if (event.getAction() == KeyEvent.ACTION_UP){
enter();
return true;
}}
return super.dispatchKeyEvent(event);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With