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);
Related
As you can see from the SSCCE I do setBanner() and setStatus() and then only add an EditField in between.
Now on a Torch, if you enter a lot of characters in the EditField until its height exceeds the area between banner and status, the last text line is overlapped by the status bar. See screenshot:
This only happens, when I set a margin for the EditField, but obviously I need this margin. Seems to be a Torch bug, since it works on other BB devices. But does anyone maybe know a workaround?
Here is the SSCCE:
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class CutOff extends UiApplication implements Runnable
{
/**
* #param args
*/
public static void main(final String[] args)
{
final CutOff bt = new CutOff();
bt.invokeLater(bt);
bt.enterEventDispatcher();
}
public void run()
{
final MainScreen s = new MainScreen();
//header
final HorizontalFieldManager head = new HorizontalFieldManager();
head.add(new ButtonField("header"));
s.setBanner(head);
//footer
final HorizontalFieldManager hf = new HorizontalFieldManager();
hf.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
hf.add(new ButtonField("test"));
final EditField f = new EditField();
f.setMargin(10, 10, 10, 10);
s.add(f);
s.setStatus(hf);
UiApplication.getUiApplication().pushScreen(s);
}
}
Thanks
Try this -
Add your EditField to a HorizontalFieldManager.
final MainScreen s = new MainScreen();
//header
final HorizontalFieldManager head = new HorizontalFieldManager();
head.add(new ButtonField("header"));
s.setBanner(head);
//footer
final HorizontalFieldManager hf = new HorizontalFieldManager();
hf.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
hf.add(new ButtonField("test"));
HorizontalFieldManager h=new HorizontalFieldManager(HorizontalFieldManager.VERTICAL_SCROLL);
final EditField f = new EditField();
f.setMargin(10, 10, 10, 10);
h.add(f);
s.add(h);
s.setStatus(hf);
UiApplication.getUiApplication().pushScreen(s);
I want to add editfield and labelfield on same line . first editfield and then buttonfield . I have tried many times but it didn't work for me .I have added horizontal field manager and also used tables but none of it can help . The issue is it is not showing the buttonfield,i can see only editfield. enter code here
public class MyScreen extends MainScreen {
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
HorizontalFieldManager m= new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
final GridFieldManager grid = new GridFieldManager(4,4,0);
grid.setColumnPadding(5);
grid.setRowPadding(5);
EditField c= new EditField("","",5,EditField.EDITABLE);
// m.add(c);
Border border=BorderFactory.createRoundedBorder(new XYEdges(10,10,10,10),Border.STYLE_SOLID);
grid.setBorder(border);
ButtonField b= new ButtonField("Select ",ButtonField.CONSUME_CLICK);
//m.add(b);
grid.insert(b,1);
grid.insert(c,0);
//add(m);
add(grid);
}
}
Override getPreferredWidth() of both EditField and ButtonField like this:
public int getPreferredWidth() {
return Display.getWidth()/2;
}
Override sublayout() and layout() method of your EditField & ButtonField than set its width Ex: 100 .. now add both this field in your m.add(); .. its works ..
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);
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.
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.