为什么整个Horizo​​ntalFieldManager可以点击?

时间:2012-10-25 06:25:15

标签: java blackberry blackberry-eclipse-plugin blackberry-jde

我在MainScreen中的setStatus方法上添加了按钮。现在整个HFM都是可点击的我不知道为什么?请指导。这是代码:

 setStatus(setFooter());
    ...
    public Field setFooter() {

            HorizontalFieldManager hfm1 = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);

            Bitmap bm;
            bm = Bitmap.getBitmapResource("statusImage.PNG");
            Background bg = BackgroundFactory.createBitmapBackground(bm, Background.POSITION_X_LEFT, Background.POSITION_Y_BOTTOM, Background.REPEAT_SCALE_TO_FIT);
            hfm1.setBackground(bg);
            hfm1.add(new DummyField(bm.getHeight()));
            hfm1.add(backButton);
            hfm1.add(nextButton);

            return hfm1;
            }

虚拟字段:

class DummyField extends Field {
    private int logoHeight;

    public DummyField(int height) {
        logoHeight = height;
    }

    protected void layout(int width, int height) {
        setExtent(1, logoHeight);
    }

    protected void paint(Graphics graphics) {
    }
}

我还重写了这些方法(lionscribe implementation)以避免HFM被点击,但它不起作用:

protected boolean touchEvent(TouchEvent message)
    {
     int event = message.getEvent();
     if (event == TouchEvent.CLICK || event == TouchEvent.UNCLICK)
     {
      // Ignore clcik events that happen outside any fields
      if (getFieldAtLocation(message.getX(1), message.getY(1)) == -1)
       return true;    // kill the event
     }
     return super.touchEvent(message);
    }

    // The regular getFieldAtLocation returns wrong values in open spaces in complex managers, so we override it
    public int getFieldAtLocation(int x, int y)
    {
     XYRect rect = new XYRect();
     int index = getFieldCount() -1;
     while (index >= 0)
     {
      getField(index).getExtent(rect);
      if (rect.contains(x, y))
       break;
      --index;
     }
     return index;
    }

1 个答案:

答案 0 :(得分:0)

我能够在Peter's post的帮助下修复它 如果字段边界条件返回false,我必须覆盖touchEvent内的CustomButtonField方法并在其中调用navigationClick

if(!( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height )) {
   navigationClick(x,y);
}