views:

142

answers:

1

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  A: 

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!

nixau
That DOES define if its consumed or not. Return true to consume, false otherwise. So, your navigationMovement was consuming the event before your moveFocus could process it. Your misreading Field's documentation. That just says to always not consume the event if this function is not overriden but the subclass. That might be a bit unclear, but it's functioning as you would expect.
Fostah
I think you didn't read problem description carefully. When I return TRUE I get different behaviour which is dependent on whether I use TRACKWHEEL or TRACKBALL. In case of TRACKWHEEL `moveFocus` IS called, on the other hand if TRACKBALL is source of event than `moveFocus` is not called.
nixau
When I return FALSE in `navigationMovement` method `moveFocus` is not called at all!
nixau