onKeyDown not registering DPAD_CENTER

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

onKeyDown not registering DPAD_CENTER

Postby Fome » Sun Dec 13, 2009 1:25 pm

Hi,

I have a really weird problem. My onKeyDown method does not react when I push the trackball on my Hero right after starting the app. I have to first trigger another DPAD-event by scrolling the ball, and then it starts registering when I click it.

I tried inserting a breakpoint in the beginning of the onKeyDown and it seems that the method isn't even called, so it has nothing to do with the code inside the method.

The same thing happens if I touch the screen -> I then have to scroll the trackball for it to start registering clicks (KEYEVENT_DPAD_CENTER).

Anyone knows how to fix this?
Fome
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 18, 2009 10:59 pm

Top

Postby Fome » Tue Dec 15, 2009 11:05 pm

I have discovered that the same thing applies to the back button. The system does not call the onKeyDown() before I have scrolled the wheel of the trackball. Instead it does the systemwide method when back-button is pressed I.E. shut down the activity.

I've been trying to fix this for hours without success. Has no one else seen this problem?
Fome
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 18, 2009 10:59 pm

Postby Fome » Wed Dec 16, 2009 12:23 am

I finally solved the problem!

I'm handling the onKeyDown in my SurfaceView-class (like in the LunarLanderexample), but for some reason, when the activity has just started, or when I have touched the screen. The Activityclass starts handling the onKeyDown events.

My solution was to Override the onKeyDown() in my activity class as well as in my SurfaceView class like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.     public boolean onKeyDown(int keyCode, KeyEvent msg){
  4.  
  5.         //_panel is the SurfaceView-class. It's onKeyDown() will return false if it didn't process the button click
  6.  
  7.         if(!_panel.onKeyDown(keyCode,msg)) return super.onKeyDown(keyCode,msg);
  8.  
  9.         else return true;
  10.  
  11.     }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Fome
Freshman
Freshman
 
Posts: 6
Joined: Wed Nov 18, 2009 10:59 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests