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
Posts: 39
Registered: ‎07-21-2008
My Device: Many
My Carrier: Many
Accepted Solution

VerticalFieldManager with fixed size : Scroll issue

Hi,

I'm trying to have a full screen UI with a fix header ( a manager with some fields) and a scrollable contents (a list of custom field). The idea is to emulate a kind of scrollable list.

For this I made a custom VerticalFieldManager that accept a maxHeight (the screen height - the header height).

I got the following problems:
- The scroll arrows do not show up (ever)
- On OS 4.7 (Storm), I can scroll lower that the last item, until having nothing on my screen but the header.

My code need to compile with the JDE 4.2.1 & 4.7 and to run on Pearl and Storm. (at worst I could have two version of this class)

I suspect the two problems are related. I probable do something wrong. I looked at a few example/forum and always found similar solution.
Do you guys can tell me what I did wrong?

    /**
     *  custom class, so we can set a max height (to keep the header visible)
     */
    class InvVerticalFieldManager extends VerticalFieldManager{
    private int maxHeight = 0;

    InvVerticalFieldManager(int _maxHeight){
      super(
       //this provoc an "empty scrollable zone" on Storm
       // but if you don't put it, on other OS, the vertical manager does not scroll at all.
       Manager.VERTICAL_SCROLL

       | Manager.VERTICAL_SCROLLBAR
       );
      maxHeight = _maxHeight;
    }
   
         
    protected void sublayout(int width, int height){
            super.sublayout(width, getPreferredHeight());
            setExtent(width, getPreferredHeight());
    }
   
    public int getPreferredWidth() {
        return Graphics.getScreenWidth();
    }

    /**
     * allow the manager to use all the given height. (vs auto Height)
     */
    public boolean forceMaxHeight = false;
    public int getPreferredHeight() {
      if (forceMaxHeight) return maxHeight;
      int m = super.getPreferredHeight();
      if (m > maxHeight) m = maxHeight;
      return m;  
    }   

    ////////////////////////////////////////////////////////////////////////////
   
    protected boolean isUpArrowShown(){
      //TODO: does not seem to work (4.2.1 emulator & 4.5 device). (called with good return value but the arrows are not painted)
      int i = getFieldWithFocusIndex();
      //Trace("isUpArrowShown " + i);
      return i > 0;
      // note: algo not correct, cause the up arrow will be visible event when no field are hidden.
      //       but not so bad, so the user "know" that he can go up.
    }
   
    protected boolean isDownArrowShown(){
      int i = getFieldWithFocusIndex();
      return i < getFieldCount();
    }
   
    ////////////////////////////////////////////////////////////////////////////
    // note : since 4.6 you can use
    // http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/ui/decor/Background.html
   
    public int myBackgroundColor = 0xffffff;
    protected void paint(Graphics g){
        g.setBackgroundColor(myBackgroundColor);
        // Clears the entire graphic area to the current background
        g.clear();
        super.paint(g);
    }
   
   
    } 

 


any helps is welcome.

 

Developer
Posts: 37
Registered: ‎09-15-2009
My Device: Not Specified

Re: VerticalFieldManager with fixed size : Scroll issue

Hi.

If you want to have only fixed header, try to make this simple solution (I use it on BB 9000)

 

..............................

add(headerElement);

VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);

vfm.add(content_element_1);

...............................

vfm.add(content_element_N);

add(vfm);

 

and you will have fixed header and scrollable content. Works on BB 9000, try on yours.

Developer
Posts: 39
Registered: ‎07-21-2008
My Device: Many
My Carrier: Many

Re: VerticalFieldManager with fixed size : Scroll issue

[ Edited ]

Hi magfed,

 

thanks for your answer.

 

I was using this solution, but on one of the phone, the header was not visible when scrolling down (and the vfm got a heigth > screen size). which is why I came with the maxHeight story.

 

Meanwhile,  I found  that you can pass a Field to setTitle ! (How could I miss that). So, my problem get solved like this:

 

- using setTitle with a XxxFieldManager for the header.

- and just adding the rest in the normal screen manager.

 

EDIT: well, the lib draw a small (4-5px) grey or black  bar under the title. this bother me pretty much.

 

 

Highlighted
Developer
Posts: 39
Registered: ‎07-21-2008
My Device: Many
My Carrier: Many

Re: VerticalFieldManager with fixed size : Scroll issue

I got it !

the solution of adding the header as the first field and the the other field in a VFM works. BUT, you must call "super(NO_VERTICAL_SCROLL)" in the MainScreen constructor.