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
huddarveena
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft
Accepted Solution

Width issue for HorizontalFieldManager nin BB OS 6.0 and 7.0

Hello all,

         I have developed a news app for BB OS 5.0, 6.0 and 7.0, which in it's Home page has a navigation bar containing different news categories. The navigation bar is designed as:

       

   public HeaderMenu(String[] categories, HeaderMenuListener listCallback) {
        super(NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR | FOCUSABLE);
        
        mCategories = categories;
        mNewsListCallback = listCallback;
        mButtons = new CustomButton[mCategories.length];
        noOfCategories = mCategories.length;
        mSelf = this;
        
        mCategoryNavigator = new HorizontalFieldManager(FOCUSABLE | HORIZONTAL_SCROLL |       HORIZONTAL_SCROLLBAR){          

              public int getPreferredWidth() {
                if (noOfCategories > 1) {
                    navigatorWidth = Display.getWidth() - mLeftNavigator.getWidth() - mRightNavigator.getWidth();
                    return Display.getWidth() - mLeftNavigator.getWidth() - mRightNavigator.getWidth();
                }
                else {
                    return Display.getWidth();
                }
            };
            
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(maxWidth, maxHeight);
                setExtent(getPreferredWidth(), getPreferredHeight());
            };
            
        };
        loadCategoryView();

        mLeftNavigator = new BitmapField(AppResolutionVariables.mLeftNavigationBtn, NON_FOCUSABLE);
        mRightNavigator = new BitmapField(AppResolutionVariables.mRightNavigationBtn, NON_FOCUSABLE);
        

        if (noOfCategories>1)
        {
            add(mLeftNavigator);
        }
        add(mCategoryNavigator);
        if (noOfCategories>1)
        {
            add(mRightNavigator);
        }
        this.setBackground(BackgroundFactory.createSolidBackground(COLOR_MAROON));
    }
    
    /**
     * Method for loading news categories in a scrollable manager.
     */
    private void loadCategoryView(){
        
        int size = mCategories.length;
        
        //Adding array of buttons representing news categories to scrollable manager.
        for(int i = 0;i < size;i++){
            String categoryName = mCategories[i];
            mButtons[i] = new CustomButton(categoryName, DATA_FONT_BOLD, DATA_FONT_PLAIN,
                                            COLOR_MAROON, COLOR_WHITE){
                
                public int getPreferredHeight() {
                    return AppResolutionVariables.mLeftNavigationBtn.getHeight();
                };
                
                protected boolean navigationClick(int status, int time) {
                    int index = Arrays.getIndex(mButtons, this);
                    if(index >= 0){
                        mNewsListCallback.notifyHeaderButtonClick(index);
                    }
                    return true;
                }
            };
            mCategoryNavigator.add(mButtons[i]);
        }
    }

    //Method takes care of laying out the left and right navigation buttons and scrollable manager in appropriate positions.
    protected void sublayout(int maxWidth, int maxHeight) {
        
        super.sublayout(maxWidth, maxHeight);
        setExtent(getPreferredWidth(), getPreferredHeight());
        
        if (noOfCategories > 1) {
            layoutChild(mLeftNavigator, maxWidth, maxHeight);
            setPositionChild(mLeftNavigator, 0, 0);
        }
        
        layoutChild(mCategoryNavigator, maxWidth, maxHeight);
        if (noOfCategories > 1) {
            setPositionChild(mCategoryNavigator, mLeftNavigator.getWidth(), 0);
        }else{
            setPositionChild(mCategoryNavigator, 15, 0);
        }
        
        if (noOfCategories > 1) {
            layoutChild(mRightNavigator, maxWidth, maxHeight);
            setPositionChild(mRightNavigator, getPreferredWidth() - mRightNavigator.getWidth(), 0);
        }
    }

 

The issue am facing is, when i scroll horizontally to last button in navigaion bar, the last button is not visible completely, it gets hidden by the right navigation button placed to extreme right of HFM. This issue is in OS 6.0 and 7.0 but not in OS 5.0.

 

Earlier I had issue in OS 5.0 as well, to fix it, I did override getPreferredWidth() of scrollable HFM above, to return the width as (width of non-scrollable HFM - width of left navigation button - width of right navigation button) and it is working fine. Can anyone please resolve the issue. Thanks in advance.

Please use plain text.
Developer
peter_strange
Posts: 19,602
Registered: ‎07-14-2008
My Device: Not Specified

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

Sorry only looking quickly here.

 

The issue I believe is in your sublayout.  You tell your mCategoryNavigator Field it has the  maximum width.  It doesn't.  It only has the width left over after the buttons have been added.

 

There are two ways you can fix this.

 

The easy way is just to pass the maximum width into the super.sublayout for mCategoryNavigator rather than maxWidth.

 

But the best way is to remove this sublayout completely, and in your sublayout for the Manager.  In that Manager, layout and position your two buttons, then give the scrolling field what is left as its maximum width.

 

Two other comments:

 

a) I would forget calling super.layout in your HeaderMenu and do everything in your own sublayout.  It would be a good exercise.  Remember the last thing you do is a setExtent, once you have positioned everything and so you know how much space you need.

 

b) If you ever call super.layout and then do a setExtent to get the size correct, alarm bells should ring.  This is a bit like giving someone a piece of paper, asking them to do a drawing, and then deciding that in fact the bit of paper is a different size to the paper they needed to do the drawing on.  You are effectively asking someone else to do something, and then ignoring what they have done (or at least part of it).  If you find you need to do it, then look for an alternate way because overriding setExtent causes the sorts of problems that you have found. 

Please use plain text.
Developer
huddarveena
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

Hello @peter_strange, I am sorry I am really not understanding what has to be done, if I remove sublayout() of the manager, then I can't layout the fields properly i.e. the right navigation button disappears. Please help me out in this regard as am newbie to BB development and if possible provide code snippet to tackle the issue. Thanks a lot.

Please use plain text.
Developer
huddarveena
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

Thank u @peter_strange your solution worked, in sublayout() of mCategoryNavigator I gave preferred width instead of maxWidth. Thank u so much.

Please use plain text.
Developer
peter_strange
Posts: 19,602
Registered: ‎07-14-2008
My Device: Not Specified

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

As noted, that is the easy way.  It is not the right way.

 

Please review my comments again.  I appreciate you are a new java developer, but if you want to play round with this sort of thing you do need to understand what you are doing.  I suggest you research this some more.  Here are some places to look:

 

http://supportforums.blackberry.com/t5/Java-Development/Create-custom-fields/ta-p/444962

 

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

 

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

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

Just to add to Peter's remarks:

Proper override of sublayout is one of the harder things in BB development to master. Every small and insignificant expression matters; the order of statements is extremely important; some seemingly innocent piece of code may be very damaging. In brief, overriding sublayout in BB OS demands respect :smileyhappy:.

 

That is why it is better to start doing all this with native, unmodified layout Managers such as HorizontalFieldManager (HFM) and VerticalFieldManager (VFM). For example, if you want a couple of buttons on the left and a horizontally scrolling part on the right, use a non-scrolling HFM, add the buttons and then a scrolling HFM to which you, in turn, add the fields belonging to the scrolling part. Those native Managers are efficient enough to not slow you down after you create a few "layers" of them.

 

I'm not trying to scare you, but to create a careful and thinking approach. Start reading the links Peter provided and experimenting with simpler things, then gradually switch to the desired complex layout.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
huddarveena
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

Thank u @peter_strange and @arkadyz, I would take up ur suggestions and work towards it. Glad to have people like u on the forums, it would help learners like us, please keep posting ur ideas, thanks again.

Please use plain text.
Developer
huddarveena
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

Hello, I have another issue related to the above code. I have a listing page which looks similar to the first image attached and when we click on row in this list, detail screen is displayed, which contains HeaderMenu(The above class), as it's first component, which looks as the second image attached.

My issue is, when we click on a row, it goes to detail page containing corresponding data to row. The HeaderMenu now contains all the data listed in listing page and when we click the focus in HeaderMenu should be on current data clicked. The focus is on the data that is clicked, but that button is not completely visible, as evident from second figure. This issue is again with OS 6.0 and 7.0 and not with 5.0. 

The focus is fine when i click on "Next" or "Previous" buttons present below the HeaderMenu. Please provide solution to the issue. I tried all possible solutions, but  still could not crack it. Thanks in advance.

first_image

 

 

second_image

 

Please use plain text.
Developer
peter_strange
Posts: 19,602
Registered: ‎07-14-2008
My Device: Not Specified

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

arkadyz is better at this sort of thing than I am but he is North America so you won't see him for a while.  So I will chip in something that I hope helps.

 

It appears you are trying to use the 'HeaderField' as a selection mechanism, so that people can go between items directly.  Is this correct?

 

It is possible that this is a similar problem to the one you have just investigated. Scrolling Managers scroll to make sure that the focused item is completely visible.  If the scrolling Manager thinks it has more width than you have actually given it, then the scroll will not move as much as it should.  Alternatively if the Field that the scrolling manager is moving to focus is actually wider than you have given it space for, a similar problem will occur. 

 

So you need to look in detail at your processing.  Review the articles I supplied plus arkadyz comments and think carefully about exactly what is happening. 

 

Hope this helps. 

Please use plain text.
Developer
huddarveena
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Width issue for HorizontalFieldManager in BB OS 6.0 and 7.0

Hi Peter, I reviewed the implementation done so far both for the manager(HeaderMenu) and button fields(CustomButton) used inside the scrollable HFM. I also read the articles provided by you carefully and checked the width of both manager and the button field. For manager am giving a width of, "Display width - (Width of left button + Width of right button)" and for button I have given width of the text being placed(using getAdvance()) plus the padding applied. 

              I could find that neither manager or button are taking extra width or are falling short of required width. I am not getting the exact problem. If you have any solution or any similar code, kindly share so that it helps to resolve the issue. Thank you.

 

 

 

Please use plain text.