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
Contributor
Posts: 24
Registered: ‎02-10-2010
My Device: 9550
My Carrier: XL
Accepted Solution

How to make a top bar as 'sticky'

[ Edited ]

Hi, everyone.

 

I want to create a sticky top bar. What i meant of a sticky top bar is where there are vertical managers that have fields extend longer than the height of the screen, the top doesn't scroll, it sticks. Maybe a good reference of this is like twitter app for blackberry. On twitter app, I assume there are 2 HorizontalFieldManager (at least I thought they are HFM), one is a title bar, and the other is button bar. Those two manager stays even if we scroll the screen.

 

I have a custom manager setup as a topbarmanager, and a middle manager, which is an intance of VerticalFieldManager, as follows

 

 

TopBarManager topMgr = new TopBarManager(logoImg);		
add(topMgr);
	
if (_menuList != null) {
	// if array is empty, just show a message
	if (_menuList.length > 0) {
		VerticalFieldManager middleMgr = new VerticalFieldManager();
		for (int i = 0; i < _menuList.length; i++) {
			MenuSelectableField menu = new MenuSelectableField(menuList[i]);
			// set listener to the menu, (when the menu is clicked).
			menu.setChangeListener(new FieldChangeListener() {
				public void fieldChanged(Field f, int context) {
					showNext(f);
				}
			});
			middleMgr.add(menu);
			middleMgr.add(new SeparatorField());
		}
		add(middleMgr);
	} else {
		LabelField label = new LabelField(
				"No menu, please check back later");
		add(label);
	}
} else {
	LabelField label = new LabelField(
			"No menu, please check back later");
	add(label);
}
// main screen background
setBackground (BackgroundFactory.createSolidBackground(Color.BLUE));

 

With the above code, the topMgr scrolls up when I scroll the screen. I want that to stay.

 

Anybody know how to do this?

 

OPrayogo
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: How to make a top bar as 'sticky'

If using a MainScreen, you can use setTitle(Field) and pass it the field you want to be at the top.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 24
Registered: ‎02-10-2010
My Device: 9550
My Carrier: XL

Re: How to make a top bar as 'sticky'

using

 

 

setTitle(topMgr);

 

 

works. But this gives me another problem as when I tried on the simulators, there is a black background being painted on the title that I cannot get rid of. ( I set up a the topMgr with a gradient background).

 

Initially, I am interested in a more 'low-level' solution. Specifically, I am more interested on how setTitle() is setup in MainScreen. The reason of that is I wanted to set up a nonscrollable bottom bar as well, and  I think this would be useful.

OPrayogo
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to make a top bar as 'sticky'

Highlighted
Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: How to make a top bar as 'sticky'

Don't call set title.

 

 

1. Set the main screen to no vertical scroll

2. Add a Field/Manager to the said main screen (This is your title)

3. Layout the field/manager manually to take however much space you want it to take

4. Add another Manager that is vertically scrollable below the title manager

5. Set the scrollable managers extent to the total height minus the title manager height

6. Profit.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: How to make a top bar as 'sticky'

For a non-scrollable bottom bar, you can use setStatus(Field). MainScreen will place it at the bottom without any of the extra decoration that comes with a title field.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 20
Registered: ‎02-15-2009
My Device: Not Specified

Re: How to make a top bar as 'sticky'

In case you need extra help there is a resource article on this:

 

http://supportforums.blackberry.com/t5/Java-Development/Create-a-screen-with-stationary-headings/ta-...

Contributor
Posts: 24
Registered: ‎02-10-2010
My Device: 9550
My Carrier: XL

Re: How to make a top bar as 'sticky'

 

 


dnepr wrote:

Don't call set title.

 

 

1. Set the main screen to no vertical scroll

2. Add a Field/Manager to the said main screen (This is your title)

3. Layout the field/manager manually to take however much space you want it to take

4. Add another Manager that is vertically scrollable below the title manager

5. Set the scrollable managers extent to the total height minus the title manager height

6. Profit.


Thanks a lot, this solved my problems.

 

 

I declared the mainscreen as such:

 

 

public MenuScreen() {
   super(Manager.NO_VERTICAL_SCROLL);
}

 

The code is of setting up the MainScreen manager:

 

 

Bitmap logoImg = Bitmap.getBitmapResource("icon_logo.png"); 
TopBarManager topMgr = new TopBarManager(logoImg);   
add(topMgr);
                     
if (_menuList != null) {
   // if array is empty, just show a message
   if (_menuList.length > 0) {
      int h = Display.getHeight() - (topMgr.getPreferredHeight() * 2);
      CustomVerticalManager middleMgr = new CustomVerticalManager(h);
      for (int i = 0; i < _menuList.length; i++) {
         MenuSelectableField menu = new MenuSelectableField(
               _menuList[i]);
         // set listener to the menu, (when the menu is clicked).
         menu.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field f, int context) {
               showNext(f);
            }
         });
         middleMgr.add(menu);
      }
      add(middleMgr);
   } else {
      LabelField label = new LabelField(
            "No menu, please check back later");
      add(label);
   }
} else {
   LabelField label = new LabelField(
         "No menu, please check back later");
   add(label);
}

BottomBarManager bottomMgr = new BottomBarManager(logoImg);
setStatus(bottomMgr);

 

 

 Kudos to Ted_Hopp too, to mention about setStatus(Field f); .

 

OPrayogo