MoveFocus is not called

I have a custom object list box with inline scrolling.

 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;
 }    

      

The scrolling works fine when I scroll the wheel, but it breaks when the app is launched on a device with a trackball. I realized that the problem lies with the moveFocus method, which is not called at all when scrolling with the trackball.

+2


source to share


1 answer


The issue was resolved by changing return true;

to return false;

in navigationMovement

. This is a good example of buggy api design. When you see some kind of gui event handling method like return boolean, your first and only suggestion is that the return value means the event was destroyed. But in case navigationMovement

you are wrong. Here's an excerpt from the JDE 4.2.1 javadoc




Parameters: dx - Amount of navigation movement: negative for moving to the left and positive for moving to the right. dy - Amount of navigation movement: negative for upward movement, and positive for downward movement. status is a bitfield of values ​​defined by the KeypadListener. time - the number of milliseconds since the device was turned on.

Returns : False (classes that extend the field should override this method to provide specific handling).

Bravo RIM!

+1


source







All Articles