I need to port my app from iPhone to blackberry, but I'm new in blckberry.
In my app I have some buttons with labels under them. It seems I cant set any views by coordinates. I should use field manager (FM) insteed. So, in this case, I need to have vertical FM for button and it's label, some horizontal FM for buttons, and vertical FM for button's forizontal FMs
(PictureBackgroundButtonField - is a class from customButtonsDemo)
VerticalFieldManager vfm = new VerticalFieldManager();
HorizontalFieldManager hfm1 = new HorizontalFieldManager();
HorizontalFieldManager hfm2 = new HorizontalFieldManager();
HorizontalFieldManager hfm3 = new HorizontalFieldManager();
VerticalFieldManager sho = new VerticalFieldManager();
shopping = new PictureBackgroundButtonField("HomePage/Home Shoping.png", Field.FOCUSABLE);
shopping.setChangeListener(this);
sho.add(shopping);
sho.add(new RichTextField("Shopping",Field.NON_FOCUSABLE));
hfm1.add(sho);
VerticalFieldManager din = new VerticalFieldManager();
dining = new PictureBackgroundButtonField("HomePage/Home Dinning.png", Field.FOCUSABLE);
dining.setChangeListener(this);
din.add(dining);
din.add(new RichTextField("Dining",Field.NON_FOCUSABLE));
hfm1.add(din);
VerticalFieldManager ent = new VerticalFieldManager();
entertainment = new PictureBackgroundButtonField("HomePage/Home Entertainment.png", Field.FOCUSABLE);
entertainment.setChangeListener(this);
ent.add(entertainment);
ent.add(new RichTextField("Entertainment",Field.NON_FOCUSABLE));
hfm1.add(ent);
VerticalFieldManager map = new VerticalFieldManager();
maps = new PictureBackgroundButtonField("HomePage/Home Maps.png", Field.FOCUSABLE);
maps.setChangeListener(this);
map.add(maps);
map.add(new RichTextField("Maps",Field.NON_FOCUSABLE));
hfm2.add(map);
VerticalFieldManager pro = new VerticalFieldManager();
promotions = new PictureBackgroundButtonField("HomePage/Home Promotions.png", Field.FOCUSABLE);
promotions.setChangeListener(this);
pro.add(promotions);
pro.add(new RichTextField("Promotions",Field.NON_FOCUSABLE));
hfm2.add(pro);
VerticalFieldManager par = new VerticalFieldManager();
parking = new PictureBackgroundButtonField("HomePage/Home Parking.png", Field.FOCUSABLE);
parking.setChangeListener(this);
par.add(parking);
par.add(new RichTextField("Parking",Field.NON_FOCUSABLE));
hfm2.add(par);
VerticalFieldManager wha = new VerticalFieldManager();
whatson = new PictureBackgroundButtonField("HomePage/Home WhatsOn.png", Field.FOCUSABLE);
whatson.setChangeListener(this);
wha.add(whatson);
wha.add(new RichTextField("What's On",Field.NON_FOCUSABLE));
hfm3.add(wha);
VerticalFieldManager moe = new VerticalFieldManager();
moeinfo = new PictureBackgroundButtonField("HomePage/Home MOEinfo.png", Field.FOCUSABLE);
moeinfo.setChangeListener(this);
moe.add(moeinfo);
moe.add(new RichTextField("MOE Info",Field.NON_FOCUSABLE));
hfm3.add(moe);
VerticalFieldManager fac = new VerticalFieldManager();
facebook = new PictureBackgroundButtonField("HomePage/Home Facebook.png", Field.FOCUSABLE);
facebook.setChangeListener(this);
fac.add(facebook);
fac.add(new RichTextField("Facebook",Field.NON_FOCUSABLE));
hfm3.add(fac);
vfm.add(hfm1);
vfm.add(hfm2);
vfm.add(hfm3);
add(vfm);
But only first of my buttons shown in every hfm*. Where are athers?
text fields use all horizontal space, so second button in horizontal field manager is outside the screen. In this case you need to sublass text field to make it's size custom, or use something else.
Related
I want my application to align two field, one to left and other to extreme left of the screen. For that i am using GridLayoutManager class. Here is my code
GridFieldManager gridFieldManager = new GridFieldManager(2,2, GridFieldManager.PREFERRED_SIZE_WITH_MAXIMUM);
gridFieldManager.add(new ButtonField("Button One"), Field.FIELD_HCENTER);
gridFieldManager.add(new ButtonField("Button Two"), Field.FIELD_RIGHT);
gridFieldManager.add(new ButtonField("HC", Field.FIELD_HCENTER));
gridFieldManager.add(new ButtonField("RT", Field.FIELD_RIGHT));
add(gridFieldManager);
And, here is my output in simulator
Can anyone please help me to align the Button Two to the extreme right of the screen ? Any help will be appreciated.
Basically it's all a matter of alignment flags and grid's column properties.
Changing the GridFieldManager style to Manager.USE_ALL_WIDTH and setting column properties to GridFieldManager.AUTO_SIZE makes all the available space to be divided evently among the two columns.
gridFieldManager.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
The following code snippet
GridFieldManager gridFieldManager = new GridFieldManager(2,2, Manager.USE_ALL_WIDTH);
gridFieldManager.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.add(new ButtonField("Button One"), Field.FIELD_LEFT);
gridFieldManager.add(new ButtonField("Button Two"), Field.FIELD_RIGHT);
gridFieldManager.add(new ButtonField("HC"), Field.FIELD_LEFT);
gridFieldManager.add(new ButtonField("RT"), Field.FIELD_RIGHT);
add(gridFieldManager);
produces
This slightly modified code snippet
GridFieldManager gridFieldManager = new GridFieldManager(1,2, Manager.USE_ALL_WIDTH);
gridFieldManager.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
VerticalFieldManager vfmLeft = new VerticalFieldManager();
vfmLeft.add(new ButtonField("Button One", Field.FIELD_HCENTER));
vfmLeft.add(new ButtonField("HC", Field.FIELD_HCENTER));
gridFieldManager.add(vfmLeft, Field.FIELD_LEFT);
VerticalFieldManager vfmRight = new VerticalFieldManager();
vfmRight.add(new ButtonField("Button Two", Field.FIELD_HCENTER));
vfmRight.add(new ButtonField("RT", Field.FIELD_HCENTER));
gridFieldManager.add(vfmRight, Field.FIELD_RIGHT);
add(gridFieldManager);
produces
Finally, to illustrate what I said previously about the available space being divided evently among the two columns, the following code snippet
GridFieldManager gridFieldManager = new GridFieldManager(1,2, Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
gridFieldManager.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setRowProperty(0, GridFieldManager.AUTO_SIZE, 0);
VerticalFieldManager vfmLeft = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
vfmLeft.setBackground(BackgroundFactory.createSolidBackground(Color.CYAN));
gridFieldManager.add(vfmLeft);
VerticalFieldManager vfmRight = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
vfmRight.setBackground(BackgroundFactory.createSolidBackground(Color.GRAY));
gridFieldManager.add(vfmRight);
add(gridFieldManager);
produces two columns of equal size.
Please use this following class.
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.container.HorizontalFieldManager;
public class HFMLeftFieldRightField extends HorizontalFieldManager {
private Field leftField;
private Field rightField;
private final static int TOP_MARGIN = 0;
private final static int LEFT_MARGIN = 30;
public HFMLeftFieldRightField() {
super(USE_ALL_WIDTH);
}
public HFMLeftFieldRightField(boolean isQatari) {
super(USE_ALL_WIDTH | Field.FIELD_LEFT);
}
public void sublayout(int maxWidth, int maxHeight) {
super.sublayout(maxWidth, maxHeight);
int width = getWidth();
if (rightField != null) {
int x = width - rightField.getWidth() - LEFT_MARGIN;
int y = TOP_MARGIN;
setPositionChild(rightField, x, y);
}
if (leftField != null) {
int y = TOP_MARGIN+rightField.getHeight()/5;
int x = LEFT_MARGIN;
setPositionChild(leftField, 0, y);
}
setExtent(maxWidth, rightField.getHeight() + TOP_MARGIN * 2);
}
public void setLeftButton(Field leftField) {
this.leftField = leftField;
super.add(leftField);
}
public void setRightButton(Field rightField) {
this.rightField = rightField;
super.add(rightField);
}
}
And add field this way.
HFMLeftFieldRightField hfm = new HFMLeftFieldRightField();
hfm.setLeftButton(new EditField("Left"));
hfm.setRightButton(new EditField("Right"));
add(hfm);
More detail http://keraisureshvblackberry.blogspot.in/2012/02/there-are-very-common-there-there-are.html
Hope helpfull..
It seems like you should use JustifiedHorizontalFieldManager instead of GridFieldManager. JustifiedHorizontalFieldManager is not a standard manager included in BlackBerry SDK, but a member of a set of UI components released by RIM later to help developers build more rich UI Interfaces. You have to download the code from here, add it to your proyect and then include the following line:
JustifiedHorizontalFieldManager justifiedManager = new JustifiedHorizontalFieldManager(buttonOne, buttonTwo, false, USE_ALL_WIDTH );
Change the style parameter of your gridFieldManager constructor to
GridFieldManager.USE_ALL_WIDTH
It should be like this
GridFieldManager gridFieldManager = new GridFieldManager(2,2,GridFieldManager.USE_ALL_WIDTH );
I want to dispaly some data at the top of the screen and some at the end of the screen,creating two different managers,the issue is after running i cannot see any data on the screen
public NativeScreen() {
super();
LabelField title = new LabelField("Calendar DatePicker",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
hrzManager = new HorizontalFieldManager() {
protected void paintBackground(Graphics graphics) {
graphics.setBackgroundColor(0x0007F5ED);
graphics.clear();
super.paint(graphics);
}
};
hrzManager.add(title);
VerticalFieldManager verticalFieldManagerUpper = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL |
Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH ) ;
verticalFieldManagerUpper.add(hrzManager);
//Add the manager to the screen.
this.add(verticalFieldManagerUpper);
VerticalFieldManager verticalFieldManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL |
Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH ) ;
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT);
ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField);
ImageButtonField bitmapField1 = new ImageButtonField(Bitmap.getBitmapResource("attachmentdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField1);
//Add the fields to the manager.
verticalFieldManager.add(horizontalFieldManager);
//Add the manager to the screen.
this.add(verticalFieldManager);
Use the set status and set title -
setTitle(field);
setStatus(field);
attempting a first Blackberry App.
It will display diary data (eventually).
I'm just trying to get things working bit by bit.
I can't get the buttons to work in the simulator ie I click them and nothing happens.
Any help appreciated.
Code is below (hopefully ok formatted - first post so apologies if not).
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
/**
* A class extending the MainScreen class.
*/
public class MyScreen extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField lastWeek;
ButtonField todayWeek;
ButtonField nextWeek;
LabelField Monday;
LabelField MondayData;
LabelField Tuesday;
LabelField TuesdayData;
LabelField Wednesday;
LabelField WednesdayData;
LabelField Thursday;
LabelField ThursdayData;
LabelField Friday;
LabelField FridayData;
LabelField Satday;
LabelField SaturdayData;
LabelField Sunday;
LabelField SundayData;
public MyScreen(){
LabelField banner = new LabelField("Diary",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField title = new LabelField("Week starting...",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Monday = new LabelField("Monday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField MondayData = new LabelField("MondayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Tuesday = new LabelField("Tuesday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField TuesdayData = new LabelField("TuesdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Wednesday = new LabelField("Wednesday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField WednesdayData = new LabelField("WednesdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Thursday = new LabelField("Thursday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField ThursdayData = new LabelField("ThursdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Friday = new LabelField("Friday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField FridayData = new LabelField("FridayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Saturday = new LabelField("Saturday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField SaturdayData = new LabelField("SaturdayData",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField Sunday = new LabelField("Sunday",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField SundayData = new LabelField("Sundaydata",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.FIELD_HCENTER);
ButtonField lastWeek = new ButtonField("<<", ButtonField.CONSUME_CLICK);
lastWeek.setChangeListener(this);
ButtonField todayWeek = new ButtonField("Today", ButtonField.CONSUME_CLICK);
todayWeek.setChangeListener(this);
ButtonField nextWeek = new ButtonField(">>", ButtonField.CONSUME_CLICK);
nextWeek.setChangeListener(this);
hfm.add(lastWeek);hfm.add(todayWeek);hfm.add(nextWeek);
hfm.setPadding(10, 0, 10, 0);
VerticalFieldManager vfm = new VerticalFieldManager(Field.FIELD_VCENTER);
vfm.add(Monday);
vfm.add(MondayData);
vfm.add(Tuesday);
vfm.add(TuesdayData);
vfm.add(Wednesday);
vfm.add(WednesdayData);
vfm.add(Thursday);
vfm.add(ThursdayData);
vfm.add(Friday);
vfm.add(FridayData);
vfm.add(Saturday);
vfm.add(SaturdayData);
vfm.add(Sunday);
vfm.add(SundayData);
add(vfm);
add(new SeparatorField());
setTitle(title);
setBanner(banner);
setStatus(hfm);
}
public void fieldChanged(Field field, int context) {
if (field == lastWeek) {
lastTextFields();
}
else if (field == todayWeek) {
todayTextFields();
}
else if (field == nextWeek) {
nextTextFields();
}
}
private void lastTextFields() {
Monday.setText("Monday-old");
MondayData.setText("MondayData-old");
}
public void todayTextFields() {
//Monday.setText("Monday");
// MondayData.setText("MondayData");
Dialog.inform("Today pressed");
}
private void nextTextFields() {
Monday.setText("Monday-new");
MondayData.setText("MondayData-new");
}
}
Since you are running your application on 8520 device simulator that doesn't have touch screen, clicking on the buttons will get you nowhere. There are several options available:
Navigate to desired button by using one of the following methods:
Use the keyboard arrow keys to navigate. Press Enter to "click" on it.
Use your mouse's scroll wheel to navigate and then left click to "click".
Press F12 to turn "trackball mode" on and use your mouse navigate. Then either press Enter or right click when the desired button is selected.
Also check this Use the trackball and other Simulating BlackBerry device interaction manuals.
Alternatively, you can compile your application with JRE 6.0 or higher and pick a use a device simulator that supports touchscreen (9800 Torch, 9930 Bold and etc...).
EDIT
You are initiating local LabelFields and ButtonFields instead of the class' member variable. All class member variable remained uninitialized (e.g. equal null). You should remove the redundant local variable definitions.
Update all your LabelFields and ButtonFields in the following way:
LabelField banner = new LabelField("Diary", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
ButtonField lastWeek = new ButtonField("<<", ButtonField.CONSUME_CLICK);
I want my button to be at the right side and bottom side. How it is possible? Please help me. My code below only displays the button on the right side but not bottom.
ButtonField b = new ButtonField("button", Field.FIELD_RIGHT | FIELD_BOTTOM);
VerticalFieldManager vf = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vf.add(b);
add(vf);
By default, a VerticalFieldManager will only use the smallest amount of vertical space necessary to display all of its children. So, your button is displaying at the bottom of the manager, but the manager is only as tall as your button. Also, a VerticalFieldManager is intended for top-down display. Try something like this:
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_BOTTOM);
ButtonField b = new ButtonField("Button", Field.FIELD_RIGHT);
vfm.add(b);
hfm.add(vfm);
add(hfm);
thanks to all. but i got my answer.
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) {
public int getPreferredWidth() {
return Display.getWidth();
}
public int getPreferredHeight() {
return Display.getHeight();
}
protected void sublayout(int maxWidth, int maxHeight) {
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
super.sublayout(displayWidth, displayHeight);
setExtent( Math.min( Display.getWidth(), getPreferredWidth() ),
Math.min( Display.getHeight(), getPreferredHeight() ) );
}
};
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_RIGHT);
ButtonField b = new ButtonField("Button", Field.FIELD_RIGHT);
vfm.add(b);
hfm.add(vfm);
add(vfm);
It's perfect work to me.
This is my screen:
final class GeneralExpenseViewScreen extends MainScreen {
public GeneralExpenseViewScreen() {
super();
LabelField title = new LabelField("TeamMate TEC | Expenses",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
Background bg = BackgroundFactory.createSolidBackground(0xBDBDDB);
setBackground(bg);
HorizontalFieldManager headerAreaManager = new HorizontalFieldManager();
HorizontalFieldManager filterAreaManager = new HorizontalFieldManager();
HorizontalFieldManager expenseListAreaManager = new HorizontalFieldManager();
HorizontalFieldManager totalAreaManager = new HorizontalFieldManager();
HorizontalFieldManager addNewAreaManager = new HorizontalFieldManager();
add(headerAreaManager);
add(filterAreaManager);
add(expenseListAreaManager);
add(totalAreaManager);
add(addNewAreaManager);
/**Begin form layouts**/
Bitmap headerImage = Bitmap.getBitmapResource("sergioheader.png");
BitmapField header = new BitmapField(headerImage);
headerAreaManager.add(header);
}
public boolean onClose() {
Dialog.alert("AH!");
System.exit(0);
return true;
}
}
Notice that I'm calling setBackground directly to the class but it's not working how I think it would work.
How can I set a background color to my application form?
Thanks.
I've used this code with success:
protected void paint(Graphics graphics) {
graphics.setBackgroundColor(0xBDBDDB);
graphics.clear();
super.paint(graphics);
}
Depending on the version you're developing for, you could use the following
getMainManager().setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
to set the screen managers background color.