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
New Developer
mdwheaton
Posts: 37
Registered: ‎07-15-2008
My Device: Not Specified

Hiding Fields in a VerticalFieldManager

[ Edited ]

I am implementing my own custom "list" of sorts.

It is composed of a VerticalFieldManager with hundreds of HorizontalFieldManagers  within it.

Each of those HorizontalFieldManagers contains a number of other fields composing the "list entry".

I want to be able to "hide" fields in the VerticalFieldManager without actually removing them from the manager.

The traditional delete(Field field) method has proved to be WAY too slow when removing many entries.

I tried some things, like extending the HorizontalFieldManager, and adding an "visible" field to it. Then, I overrode the following methods

 

    public int getPreferredHeight()
    {
      if (this.visible)
        return super.getPreferredHeight();
      return 0;
    }

    public int getPreferredWidth()
    {
      if (this.visible)
        return super.getPreferredWidth();
      return 0;
    }

    public int getVisibleHeight()
    {
      if (this.visible)
        return super.getVisibleHeight();
      return 0;
    }

    public int getVisibleWidth()
    {
      if (this.visible)
        return super.getVisibleWidth();
      return 0;
    }

    protected void sublayout(int maxWidth, int maxHeight)
    {
      if (this.visible)
      {
        super.sublayout(maxWidth, maxHeight);
        return;
      }
      else
      {
        super.sublayout(0,0);
        setExtent(0,0);
      }
    }

    protected void subpaint(Graphics graphics)
    {
      if (this.visible)
        super.subpaint(graphics);
    }

 

This "ALMOST" worked and was lightning fast.

It did not draw the elements on the screen, but the placeholder was still there in the VerticalFieldManager

For instance, if each element was 40 pixels high, and I marked elements 2 and 3 as not visible, then I would have an 80 pixel gap between elements 1 and 4. Also, I had some focusable elements in the HorizontalFieldManager that were still focused to, even though they were not drawn.

 

 

Is there a method I can override in the VERTICALFieldManager that contains the elements to selectively draw and layout the children that are marked with the visible attribute and NOT allocate any space to the ones marked NOT visible?

 

 

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

Re: Hiding Fields in a VerticalFieldManager

Sorry not an answer!  Just to say that I too am looking for this, i.e. a way to ask a Manager to lay itself out again.  In my case I have a Field that has changed size, and I want the Manager to detect this change.  invalidate( does not do it, removing and adding the Field does, but that is not a desirable solution.

 

I guess we could extend the Manager and make layout public, but I suspect there is an official way to do this.

Developer
Developer
gtj
Posts: 319
Registered: ‎07-20-2008
My Device: Not Specified

Re: Hiding Fields in a VerticalFieldManager

I wonder if adding/removing a single null field will cause the re-layout?

 

Developer
Developer
mb1
Posts: 320
Registered: ‎05-26-2009
My Device: Not Specified

Re: Hiding Fields in a VerticalFieldManager

I model this by doing the following and it works on all OSes >= 4.2.

 

  1. Hide --> delete the field from the manger.  Use deleteRange(startIndex, number) to delete the fields, to get the startIndex use Field.getIndex for field to delete.
  2. Reinsert: Reinsert the field you deleted useing insertElement
  3. If you are using a ListField, simply remove the object form the internalList that your extended class.

 

If you want the Screen to automatically handle delete/insert by looking at the state of some data structures  you could look at Screen.onExposed and Screen.onDisplay.  But I have found this approach to not work reliably across OS versions (even on the emulator).

 

--MB.

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

Re: Hiding Fields in a VerticalFieldManager

Thanks gti, just tried adding and removing a NullField.  Nice idea, however that did not work for me.  I also tried a LabelField.  It seems that the managers only layout the Fields once.  Clearly there are ways around this - the BasicEditField must do something when it goes onto a second line.  But what?!

 

mb1 - we are aware of the possibilities of adding and deleting, the problem for the original poster was the number of adds/deletes required was large and he was finding this time consuming.  I agree, in my testing I was adding/deleting 30 Fields and that took about 5 seconds on a 8320 that I was testing on.  For me, the problem is that I want to resize a BasicEditField, if I remove it I loose the current cursor position and focus, getting it back is possible, but the screen shifts round while I am doing this.

 

I could just find out to force the manager to layout my Field again, I would be happy. 

 

 

Developer
Kenjkelly01
Posts: 64
Registered: ‎01-12-2009
My Device: Blackberry Storm, Curve, Tour

Re: Hiding Fields in a VerticalFieldManager

Sorry I'm late for the question but incase someone else runs across this thread, to force a re-layout of a field try:

 

getManager().setFont(getManager().getFont());

 

That forces the manager to relayout its fields.

 

 Ken Kelly

Ken J Kelly
New Developer
CobiRic
Posts: 21
Registered: ‎03-31-2011
My Device: Developer

Re: Hiding Fields in a VerticalFieldManager

Nice, just a reminder that to other new guys like me: this needs to be done on the UI thread.
www.cobiinteractive.com
www.madmob.co.za
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Hiding Fields in a VerticalFieldManager


Kenjkelly01 wrote:

Sorry I'm late for the question but incase someone else runs across this thread, to force a re-layout of a field try:

 

getManager().setFont(getManager().getFont());

 

That forces the manager to relayout its fields.

 

 Ken Kelly


Or simply invoke updateLayout() :smileywink:

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Developer
CobiRic
Posts: 21
Registered: ‎03-31-2011
My Device: Developer

Re: Hiding Fields in a VerticalFieldManager

... where were you when this was first posted? ...

 

Thanks, and this method can be called from outside the UI thread.

www.cobiinteractive.com
www.madmob.co.za
Developer
donturner
Posts: 135
Registered: ‎11-14-2010
My Device: BlackBerry Z10 (White)

Re: Hiding Fields in a VerticalFieldManager

[ Edited ]

Just to add, I don't think this method can be called outside the UI thread, so you will need to use: 

 

UiApplication.getUiApplication().invokeLater(new Runnable(){
			
	public void run(){
		updateLayout();
	}
});

 

Unless someone knows a better way of calling this...