If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Remove Dynamically Fields issue (left )

I am confident that your problem is a bug in GridFieldManager.  I recommend that you replace this with your own Manager. 

 

To test this, I changed your code to paint a rectangle around the outside of the Label and the Button, and the button rectangle moves sideways after a delete.  This means that GridFieldManager is repositioning the fields, whihc of course it should not do.

 

In case you are interested, my updated code is included at the end of this post.

 

Given this, I would remove GridFieldManager.  You could replace it with TablelayoutManager (search the forum I'm sure you will find references to this).  But in your case, the Manager is just laying out two Fields - this is a good sample to try out writing your own Manager.  Review these and give it a go:

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

 

The way you use GridFieldManager is a bit odd anyway, you would not usually use it in circumstances where rows are deleted. 

 

I would change the code in your Customer Button for onFocus and onUnfocus to something like the following - your current code will not work as you expect because you have overridden the wrong unfocus method signature.

 

 

 protected void onFocus(int direction){
  focus = true;
  button = on;
  super.onFocus(direction);
  invalidate();
 }
 
 protected void onUnfocus(){
  focus = false;
  button = off;
  super.onUnfocus();
  invalidate();  
 }

 

 

Minor point, next time you create some test code, please try it yourself - you did not include the assets that the code needed which meant I had to do some faffing round..... 

 

Finally here is the updated code to draw the rectangles:

 

  _btnRemove = new CustomImageButton(_bitmapDelete, Field.FIELD_RIGHT
    | Field.FOCUSABLE) {
   protected void paint(Graphics graphics) {
    super.paint(graphics);
    int currCol = graphics.getColor();
    try {
     graphics.setColor(0x00000000); // Black
     graphics.drawRect(0, 0, this.getWidth(), this.getHeight());
    } finally {
     graphics.setColor(currCol);
    }
   }
  };

 

  _lblName = new LabelField(_subject, Field.FIELD_TOP | Field.FOCUSABLE
    | Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT) {
   protected void paint(Graphics graphics) {
    super.paint(graphics);
    int currCol = graphics.getColor();
    try {
     graphics.setColor(0x00000000); // Black
     graphics.drawRect(0, 0, this.getWidth(), this.getHeight());
    } finally {
     graphics.setColor(currCol);
    }
   }
  };

Please use plain text.