moveFocus is not called

767 Views Asked by At

I have a custom object list field with implemented scrolling routine.

 public int moveFocus(int amount, int status, int time) {
  invalidate(getSelectedIndex());

  int unused = super.moveFocus(amount, status, time);
  return Math.abs(unused) + 1;
 }

 public boolean navigationMovement(int dx, int dy, int status, int time) {
  if (dy > 0) {
   if (selectedIndex < getSize() - 1) {
    setSelectedIndex(selectedIndex + 1);    
   }
  } else if (dy < 0) {
   if (selectedIndex > 0) {
    setSelectedIndex(selectedIndex - 1);
   }
  }

  return true;
 }    

Scrolling works fine when I scroll with trackwheel, but gets broken when app is launched on a device with trackball. I figured out that problem lays in framework method moveFocus which is not called at all when I scroll with trackball.

1

There are 1 best solutions below

3
On

Issue has been resolved by changing return true; to return false; in navigationMovement method. This makes a good example of a buggy api design. When you see some gui event handling method like this returning boolean your first and only suggestion is that the return value means the event has been consumed. But in case of navigationMovement method you're wrong. Here's an extract from JDE 4.2.1 javadoc


Parameters: dx - Magnitude of navigational motion: negative for a move left and postive for a move right. dy - Magnitude of navigational motion: negative for an upwards move, and positive for a downwards move. status - Bitfield of values defined by KeypadListener. time - Number of milliseconds since the device was turned on.

Returns: False (classes that extend Field must override this method to provide specific handling).

Bravo RIM!