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: 96
Registered: ‎03-06-2009
My Device: Not Specified
Accepted Solution

Linking several HorizontalFieldManager

Hello,

 

I created an array using several HorizontalFieldManager that I put below each other.

 

Problem is only the current row moves when I scrool horizontally but (logically) not the rest of the array.

So it messes the display up.

 

Do you know how I could do to make all the other HorizontalFieldManager of the array move at the same time when one of them moves?

Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Linking several HorizontalFieldManager

just to clarify:
you have several hfm that contain more fields then the screen can hold (and thus show a scrollbar).
if you now scroll right in one of them you want all of them scrolling?
setHorizontalScroll would be the method of choice, then.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 96
Registered: ‎03-06-2009
My Device: Not Specified

Re: Linking several HorizontalFieldManager

they don't show a scrollbar but several fields get out of the screen on the right side, yes.

When I scroll right only the fields of the current hfm scroll but I'd like other fields from others hfm to scroll too.

 

Could you explain what's I would have to do with setHorizontalScroll (put it on all the hfm? what should i put in its body then?)

 

thanks

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Linking several HorizontalFieldManager

What you will probably want to do is override the HFM and create a setHorizontalScroll2() that calls super.setHorizontalScroll(). Make setHorizontalScroll() call setHorizontalScroll2() for all HFMs in the array. This way they can all be focusable and you won't run into loops of calling the scroll function.
Developer
Posts: 96
Registered: ‎03-06-2009
My Device: Not Specified

Re: Linking several HorizontalFieldManager

Ok thanks I got what you meant.

However I'm using JDK 1.3 (it's for a blackberry application and I don't have a choice).

 

Do you know how I could do without the @Override (which isn't supported in 1.3)?

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Linking several HorizontalFieldManager

[ Edited ]

private class MyHorizontalFieldManager extends HorizontalFieldManager { protected void setHorizontalScroll2( int horizontalScroll ) { super.setHorizontalScroll( horizontalScroll ); } protected void setHorizontalScroll( int horizontalScroll ) { // loop through your array setHorizontalScroll2( horizontalScroll ); } }

 

Message Edited by mreed on 03-16-2009 11:36 AM
Developer
Posts: 96
Registered: ‎03-06-2009
My Device: Not Specified

Re: Linking several HorizontalFieldManager

Ok I get it, thanks.

However, I just tried it and the method setHorizontalScroll doesn't seem to be called when I go to the right of the screen to make it scroll.

 

Is this function fired automatically? because in the javadoc I found this: This method is not normally invoked as focus movement deals with scrolling automatically. (http://www.blackberry.com/developers/docs/4.1api/net/rim/device/api/ui/Manager.html#setHorizontalScr...))

 

 

Highlighted
Developer
Posts: 96
Registered: ‎03-06-2009
My Device: Not Specified

Re: Linking several HorizontalFieldManager

Oops, forgot to set the listener.

 

this.setScrollListener(new ScrollChangeListener() { public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll) { setHorizontalScroll(newHorizontalScroll); } });

 

Thanks

New Developer
Posts: 5
Registered: ‎07-20-2008
My Device: Not Specified

Re: Linking several HorizontalFieldManager

This thread very closely reflects what I'm trying to accomplish with a slight twist.  I'm using 4.2.1 and have successfully setup a row lable VerticalFieldManager and an associated grid with all scrolling working just as I want them to.  What I haven't been able to accomplish is having a vertically fixed title region that also scrolls horizontally with my grid (to allow column labels to scroll with the data in the grid, as you scoll down it needs to remain fixed vertically but scroll horizontally.)  I've used setTitle to place the column lable HorizontalFieldManager but haven't figured out how to get it to scroll horizonally in lockstep with the underlying data grid.  I've overridden HorizontalFieldManager as follows and use it exclusively in this class:

 

    private class myHorizontalFieldManager extends HorizontalFieldManager implements ScrollChangeListener {
       
        protected void setHorizontalScroll2( int horizontalScroll ) {

            super.setHorizontalScroll( horizontalScroll );

        }
     
        public void setHorizontalScroll( int horizontalScroll ) {

// Attempts to break on this line do not occur when scrolling:

            setHorizontalScroll2( horizontalScroll );
        }

        public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll) {

// Attempts to break on this line do not occur when scrolling in the simulator

            manager.setHorizontalScroll(newHorizontalScroll);
       }

   }

 

Field manager configuration-related code (my class extends MainScreen):

 

 

        VerticalManager1 = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Field.NON_FOCUSABLE){
                    protected void sublayout(int width, int height) {
                    super.sublayout(Display.getWidth()/3, height);
                }
        };
       
        VerticalManager2 = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.HORIZONTAL_SCROLL){
                    protected void sublayout(int width, int height) {
                    super.sublayout((Display.getWidth()/3)*2, height);
                }
        };

        HorizontalManager1 = new myHorizontalFieldManager(){
                    protected void sublayout(int width, int height) {
                    super.sublayout(Display.getWidth()/3, height);
                }
        };
       
        HorizontalManager2 = new myHorizontalFieldManager(){
                    protected void sublayout(int width, int height) {
                    super.sublayout((Display.getWidth()/3)*2, height);
                }
        };

.

.

.

 

       VerticalManager2.add(grid);

// placeholder for use in my title region for the row lable portion

       HorizontalManager3.add(HorizontalManager1);

// column labels to place in the title region

       HorizontalManager3.add(HorizontalManager2);

 

// I can add the column lables effectively using setTitle but havent figured out how to get them to scroll in lockstep

       setTitle(HorizontalManager3);

// VerticalManager1 contains the row lables, works perfectly (scrolls vertically but not horizontally)
       mainHorizontalManager.add(VerticalManager1);

// VerticalManager2 contains the data grid itself, all scrolling works just as desired
       mainHorizontalManager.add(VerticalManager2);

       add(mainHorizontalManager);

       this.setScrollListener(new ScrollChangeListener() {
            public void scrollChanged(Manager manager, int newHorizontalScroll, int newVerticalScroll) {

// Attempts to break on this line do not occur when scrolling in the simulator

                setHorizontalScroll(newHorizontalScroll);
            }
       });

So my biggest challenge right now is just getting scroll actions to throw scollChange which I believe would give me the ability to call setHorizontalScroll for the column label myHorizontalManager object.  Any suggestions on what I'm missing are greatly appreciated.  Also if it is not possible to scroll horizontally within a title region that would be great to know before I go too much further down that path.