0

我在 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;
    }
4

1 回答 1

0

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

if(!( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height )) {
   navigationClick(x,y);
}  
于 2012-10-29T06:05:52.453 回答