Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onKeyDown() issue

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?

like image 705
Niko Gamulin Avatar asked Jun 10 '09 10:06

Niko Gamulin


People also ask

What is the return value of onKeyDown () method?

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).

What is the event for onKeyDown?

The onkeydown event occurs when the user is pressing a key (on the keyboard).

What does onKeyDown mean in HTML?

The onkeydown attribute fires when the user is pressing a key (on the keyboard).


1 Answers

I had a similar problem and solved it by adding

this.requestFocus();
this.setFocusableInTouchMode(true);

in the constructor of my SurfaceView subclass.

like image 107
Ciryon Avatar answered Oct 05 '22 23:10

Ciryon