views:

17

answers:

2

i am working on blackberry curve 8300

i have added some components in the main screen,now i want to move the focus vertically when the trackball moves up or down and move the focus horizontally when track-Wheel moves left or right.

==================================================================================

--Title area that contains a focusable field(BACK)--
--Non focusable Label field that indicates the name of the user--
--A horizontal field manager1 that contains 4 buttons--
--A horizontal field manager2 that contains 4 buttons--
--A horizontal field manager2 that contains 4 buttons--

==================================================================================

now suppose currently focus is on BACK button and i scroll the track-wheel downwards then, focus should come on 1st button of manager1 Again when i scroll downwards,then focus should come on the 1st button of manager2 and not the 2nd button of manager1(as its happening on device)

my code is :::

protected boolean trackwheelRoll(int amount, int status, int time) 
{
 focusIndex = this.getFieldWithFocusIndex();
 System.out.println("focus index ::::::::::::::::"+focusIndex);
 Field f;
 if(focusIndex!=0)
 {
   if(amount==-1)
   {
    //move up
       if(focusIndex>=0)
       {
        focusIndex = focusIndex-1;
         f = getField(focusIndex);
         f.setFocus();      
       }
   }
   if(amount==1)
   {
    //moving down
        if(focusIndex<=3)
        {
           f = getField(++focusIndex);
           f.setFocus();
        }
   }
     }
 return super.trackwheelRoll(amount, status, time);
}

even after this control moves abruptly on simulator but on device no change took place

+1  A: 

Try overriding the [navigationMovement][1] method instead of trackwheelRoll - you'll have access to the "dx" and "dy" parameters so you can tell whether they are scolling up/down or side-to-side. The trackwheelRoll method is somewhat archaic now that there are no more trackwheel devices.

[1]: http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/Manager.html#navigationMovement(int, int, int, int)

Marc Novakowski
your idea worked!!!i tried navigation movementi realised that trackwheel does not work on devices having space-pad or trackball
SWATI
A: 
protected boolean navigationMovement(int dx, int dy, int status, int time) 
 {
    Field f;
    int index;
    focusIndex = this.getFieldWithFocusIndex();
    if(focusIndex==1)
    {
        f = getField(focusIndex);

        Manager m = (Manager)f;
        index = m.getFieldWithFocusIndex();
        if(dx==-1)
        {
            index = index--;
            if(index>=0)
              {
                f = m.getField(index);
                f.setFocus();
              }
        }
        if(dy==-1)
        {
            index = index-3;
            if(index>=0)
              {
                f = m.getField(index);
                f.setFocus();
              } 
        }
        if(dx==1)
        {
            index = index++;
            if(index<=19)
              {
                f = m.getField(index);
                f.setFocus();
              } 
        }
        if(dy==1)
        {
            index = index+3;
            if(index<=19)
              {
                f = m.getField(index);
                f.setFocus();
              } 
        }
    }
    return super.navigationMovement(dx, dy, status, time);
}
SWATI