I would like to create a photo/video capture application.
I have created a CaptureView
class which extends SurfaceView
and placed it in the main form.
The main form's activity has onCreateOptionsMenu()
method which creates a menu. The menu worked fine but then I tried to implement a method onKeyDown
:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN) {
switch(keyCode) {
case KeyEvent.KEYCODE_CAMERA:
videoPreview.TakePicture();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
The menu doesn't appear anymore and the method doesn't catch onKeyDown event.
Does anyone know what could be the reason for this issue?
onkeyDown() - this puts the burden on super class to handle the onKeyDown event by your own wish (You explicitly say to handle it). when you return false , android assumes that you have not handled the onKeyDown event and super. onKeyDown() gets called by default (without you calling it).
The onkeydown event occurs when the user is pressing a key (on the keyboard).
The onkeydown attribute fires when the user is pressing a key (on the keyboard).
I had a similar problem and solved it by adding
this.requestFocus();
this.setFocusableInTouchMode(true);
in the constructor of my SurfaceView subclass.
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