0

I need to add onKeyUp()/onKeyDown() event handling to my application, in which I did not create the Activity and main View. (Getting OuyaController working with a Marmalade SDK application).

With onGenericMotion() it seems straightforward (view.setOnGenericMotionListener()), however I'm confused about view.setOnKeyListener(), as the interface of the android.View.OnKeyListener that it takes as an argument has a single onKey() method, and not onKeyUp()/onKeyDown().

Apparently, view.KeyEvent.Callback has this interface, which Activity and View implement - what class has this interface and how can I add its functionality to a View procedurally?

zyndor
  • 1,418
  • 3
  • 20
  • 36

2 Answers2

0

I don't think you can add any method or event handling in any activity which you didn't create. The best possible solution would be to subclass the Activity, add your modification and use that class instead.

0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
0

The onKey method will pass you a KeyEvent. Check getAction() for ACTION_UP, ACTION_DOWN and ACTION_MULTIPLE states.