user-interfaceblackberrylistfield

How do you limit the overall height of a ListField?


I'm trying to limit the height of a ListField, so that instead of moving down the screen when you move through the items, you only move down inside the box. So, for example, the header on the screen wouldn't disappear.

My current solution doesn't work. The height doesn't change. It stills stays at whatever size the list of objects is. The code I'm using is:

_listField = new ListField()
    {
        protected void layout(int w, int h)
        {
            super.layout(w, 100);
        }
    };

Solution

  • You can do this way. In your MainScreen constructor add

    super(NO_VERTICAL_SCROLL);
    

    so your mainscreen will not scroll.

    create new manager which has vertical scrolling enabled so only manager will be scrollable like

    VerticalFieldManager listManager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR); 
    

    Now add your components to this manager say your ListField like

    listManager.add(your listfield object);
    

    If you want to limit the height of listField, then you can set the limit to listManger and add the listfield to manager. so list will be layout in given height of manger like this

    VerticalFieldManager listManager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR); 
    {
        protected void sublayout( int maxWidth, int maxHeight )
        {
             int width = Display.getWidth();
             int height = 100;
             super.sublayout( width, height);
             setExtent( width, height);
        }
    };
    

    Hope this will help you.