Horizontal blackberry file manager - blackberry

i have a horizontal file manager on a screen ...and a vertical field manager inside the horizontal field manager..but the height of the vertical field manager increases and decreases due to adding and deleting fields dynamically... and the height of the horizontal file manager changes accordingly which i don't want...i want to fix the height of the horizontal file manager to a specific height..which would be max val for vertical field manager...
how can i do this...

try this code
HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR){
protected void sublayout(int maxWidth, int maxHeight) {
maxHeight = specificHeight;
super.sublayout(maxWidth, maxHeight);
}
};

Related

BlackBerry: setting the height of a field manager without manually building the layout

I want to set the height of a manager so that my tab bar sits perfectly beneath the manager at the bottom of the screen.
I'd add my vertical field manager which holds all the content, then I add(tabbar).
The problem is that when I use the following, all the fields disappear. However, the height is set the way I want it.
bottom_vfm = new VerticalFieldManager() {
protected void sublayout(int maxWidth, int maxHeight) {
setExtent(maxWidth, 200);
}
};
Do I have to manually setChildPosition and layoutChild for every field? Is there any way around it?
have u tried like this?
bottom_vfm = new VerticalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight){
super.sublayout(maxWidth,200);
setExtent(maxWidth,200);
}
};

setting the position of a button in blackberry java

how to set the position of a button in java blackberry.
You can position a button or any other component on a screen by creating a Manager class and overriding the sublayout() method. A Manager is kind of like a Panel in java i.e an area of the screen you can add components to. In the sublayout() method you should
set the size of the component with layoutChild()
set the position of the component with setPositionChild()
Set the overall size of the Manager with setExtent()
something like
button = new ButtonField();
HorizontalFieldManager manager = new HorizontalFieldManager(){
protected void sublayout(int width, int height) {
int buttonWidth = button.getPreferredWidth();
int buttonHeight = button.getPreferredHeight();
layoutChild(button,buttonWidth, buttonHeight);
setPositionChild(button, 0, 0);
setExtent(width, height);
}
};
manager.add(button);
You can override getPreferredWidth() and getPreferredHeight() for your button if you want to specify a certain width and height.
See
Custom layout Manager
Manager class

BlackBerry HorizontalFieldManager alignment

Horizontally, I want to display two bitmaps, and between them display a label field.
The code seems straightforward, but all the fields are added on the left side of the screen.
HorizontalFieldManager hfm = new HorizontalFieldManager();
callbmp = new BitmapField(ei.getBitmap(),Field.FOCUSABLE |BitmapField.FIELD_LEFT);
LabelField NAME = new LabelField("mylable", LabelField.FIELD_HCENTER);
mailbmp = new BitmapField(mail.getBitmap(),Field.FOCUSABLE|BitmapField.FIELD_RIGHT);
hfm.add(callbmp);
hfm.add(NAME);
hfm.add(mailbmp);
add(hfm);
Manager customManager = new Manager(0)
{
protected void sublayout(int width, int height) {
setPositionChild(
getField(0),
0,
0);
layoutChild(
getField(0),
getField(0).getPreferredWidth(),
getField(0).getPreferredHeight());
setPositionChild(
getField(1),
Graphics.getScreenWidth()/2 - getField(1).getPreferredWidth()/2,
0);
layoutChild(
getField(1),
getField(1).getPreferredWidth(),
getField(1).getPreferredHeight());
setPositionChild(
getField(2),
Graphics.getScreenWidth() - getField(2).getPreferredWidth(),
0);
layoutChild(
getField(2),
getField(2).getPreferredWidth(),
getField(2).getPreferredHeight());
setExtent(width, height);
}
};
customManager.add(new BitmapField(Bitmap.getBitmapResource("image1.png")));
customManager.add(new LabelField("Hello Alignment"));
customManager.add(new BitmapField(Bitmap.getBitmapResource("image2.png")));
HorizontalFieldManager lays out the fields left-to-right in the order in which they are added. The style bits for horizontal layout are ignored.
If you want left, right and center on a horizontal line, you'll need a custom manager.
This should be your requirement:
It can be done simply by subtracting the widths of the items you are adding on your horizontal field manager. By default the leftButton or the first item you add on the HFM will be added on left. Then you can add your label(userName) and the rightButton in the following way:
LabelField userName = new LabelField("MaheshBabu");
HorizontalFieldManager horizontalBar = new HorizontalFieldManager(USE_ALL_WIDTH|Manager.NO_HORIZONTAL_SCROLL|Manager.NO_HORIZONTAL_SCROLLBAR);
horizontalBar.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
rightButton.setMargin(0, 0, 0, Display.getWidth()-rightButton.getPreferredWidth()-leftButton.getPreferredWidth()-userName.getPreferredWidth());
horizontalBar.add(leftButton);
horizontalBar.add(userName);
horizontalBar.add(rightButton);

Can't align fields horizontally on custom pop up screen in Blackberry

What I want to achieve is to have a custom popup screen with specified width and height.
On that screen I add two buttons which stay in one row and align center horizontally.
public class CustomPopupScreen extends PopupScreen {
ButtonField minimizeBf;
ButtonField cancelBf;
HorizontalFieldManager hfm;
public CustomPopupScreen() {
super(new VerticalFieldManager());
minimizeBf = new ButtonField("Minimize", FIELD_HCENTER|Field.USE_ALL_WIDTH);
cancelBf = new ButtonField("Cancel", FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm = new HorizontalFieldManager(FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm.add(minimizeBf);
hfm.add(cancelBf);
add(hfm);
//add(minimizeBf);
//add(cancelBf);
}
protected void sublayout(int width, int height) {
// TODO Auto-generated method stub
int xPos = 0;
int yPos = 0;
int sideMargin = 30;
int screenWidth = width - (2 * sideMargin);
int screenHeight = 100;
layoutDelegate(screenWidth, screenHeight);
//setPositionDelegate(0, 0);
super.sublayout(screenWidth, screenHeight);
setExtent(screenWidth, screenHeight);
xPos = (width - screenWidth) / 2;
yPos = (height - screenHeight) / 2;
setPosition(xPos, yPos);
// layout(screenWidth, screenHeight);
}
}
If I add those buttons to the screen, then it will align center horizontally, but the buttons appear on different row, while I want it to appear in the same row.
Can somebody tell me where have I code wrong ?
Try removing the USE_ALL_WIDTH flag from your HorizontalFieldManager allocation. That should do the trick.
Try putting a couple of vertical field managers, each taking half the available width, inside the horizontal manager. then add one button to each of the vertical managers.
I was just wondering the purpose of having a custom size. There is often a correct way to do something without having to modify the layout manually. If you share your end goal, we may be able to help better. Since it almost appears that you want to simply make two buttons be side to side. To add width and height you can add spacers (add(new SeparatorField())) to the field managers and specify their width/height as well as where in the manager you want them. This would allow all the fields to use their default layout patterns.
just do one
hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
i think it might help you just give it a try.

Placement of ButtonField

i want to place the Buttons as displayed in the image:
alt text http://www.freeimagehosting.net/uploads/413b8990b3.png
for this i am using the following code but it is not working for me can any one please help me out
topbarManager = new HorizontalFieldManager();
topbarLeftManager = new HorizontalFieldManager(Field.FIELD_LEFT);
topbarRightManager = new HorizontalFieldManager(Field.FIELD_RIGHT);
topbarCenterManager = new HorizontalFieldManager(Field.FIELD_HCENTER);
topbarLeftManager.add(new ButtonField("first"));
topbarRightManager.add(new ButtonField("second"));
topbarCenterManager.add(new ButtonField("third"));
topbarManager.add(topbarLeftManager);
topbarManager.add(topbarCenterManager);
topbarManager.add(topbarRightManager);
i am not getting the result as i required.
can any one please Help me out.
Thanks a lot
according to docs.
HorizontalFieldManager layout manager arranges UI components in a single horizontal row starting at the left side of the screen and ending at the right side of the screen. Because this layout manager arranges UI components horizontally, you cannot apply horizontal style bits to UI components (for example, Field.FIELD_LEFT, Field.FIELD_HCENTER, or Field.FIELD_RIGHT). You can apply vertical style bits (for example, Field.FIELD_TOP, Field.FIELD_BOTTOM, or Field.FIELD_VCENTER).
so if you want to see Field.FIELD_LEFT effect use
VerticalFieldManager hfm = new VerticalFieldManager(Manager.USE_ALL_WIDTH);
instead of HorizontalFieldManager, you will see the stair case like effect.
To layout UI best thing is use custom layout
HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.USE_ALL_WIDTH){
protected void sublayout(int maxWidth, int maxHeight) {
Field f;
int w = Display.getWidth();
int x=0;
for (int i = 0; i < getFieldCount(); i++) {
f = getField(i);
layoutChild(f, f.getPreferredWidth(), f.getPreferredHeight());
setPositionChild(f, x, 0);
x+=(w-f.getWidth())/2;
}
setExtent(maxWidth, maxHeight);
}
};

Resources