0

I have added buttons on my setStatus method in the MainScreen. Now the entire HFM is clickable I don't know why? Please guide. Here's the code:

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

The dummy field:

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

I have also overridden these methods(lionscribe implementation) to avoid HFM from being clickable but it doesn't work:

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;
    }
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
Atif Imran
  • 1,899
  • 2
  • 18
  • 33

1 Answers1

0

I was able to fix it with the help of Peter's post I had to override the touchEvent method inside my CustomButtonField and called navigationClick inside it if the field boundary condition returned false:

if(!( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height )) {
   navigationClick(x,y);
}  
Atif Imran
  • 1,899
  • 2
  • 18
  • 33