开发者

Android SurfaceView Problem

Whilst drawing on a SurfaceView, I'm having a problem intercepting a 'back' key press. My onKeyDown event only seems to get called on the 2nd and subsequent key events - which is useless for the back key because by the activity has already paused or terminated.

I have tried every suggestion I have come across, making sure focusable and touchmodefocusable are set etc, moving my onkeydown handler out of the View and into the activity etc. It works the same on the emulator and on hardware.

I know this has something to do with focus, but it seems I cant get my surfaceview to recieve focus for Key Events and Touch Events at the same time.

Please help I am get开发者_高级运维ting seriously miffed with this as I cant understand why no one else has this problem.

Thanks.


Solved this - for some reason using a requestFocus() call 'before' setting the setFocusable(true) flags did the trick. whodathunkit. btw this is done in the surface view constructor.

Copied this to an answer in case it helps anyone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜