1

我正在研究黑莓曲线 8300

我在主屏幕中添加了一些组件,现在我想在轨迹球向上或向下移动时垂直移动焦点,并在轨迹轮向左或向右移动时水平移动焦点。

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

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

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

现在假设当前焦点在 BACK 按钮上,然后我向下滚动拨轮,焦点应该出现在 manager1 的第一个按钮上,当我再次向下滚动时,焦点应该出现在 manager2 的第一个按钮上,而不是 manager1 的第二个按钮上(因为它发生在设备上)

我的代码是:::

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

即使此控件在模拟器上突然移动但在设备上也没有发生变化

4

2 回答 2

2

尝试覆盖 [navigationMovement][1] 方法而不是 trackwheelRoll - 您将可以访问“dx”和“dy”参数,以便您可以判断它们是向上/向下还是左右滑动。由于没有更多的滚轮设备,因此 trackwheelRoll 方法有些过时。

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

于 2010-04-30T15:39:19.173 回答
1
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);
}
于 2010-05-01T06:18:28.880 回答