I keep getting an IllegalArgumentException and nothing shows on the BlackBerry simulator when I run this code. What could be wrong with it?
public MyScreen()
{
// Set the displayed title of the screen and add the weather icons
setTitle("PixWeather");
cityField = new LabelField("Queensland", Field.FIELD_LEFT);
tempField = new LabelField("17", Field.FIELD_RIGHT);
condField = new LabelField("sunny",Field.FIELD_RIGHT);
weather_icon = Bitmap.getBitmapResource("sun_icon.png");
bitmapField = new BitmapField(weather_icon, Field.FIELD_LEFT);
VerticalFieldManager vfield = new VerticalFieldManager();
HorizontalFieldManager hfield1 = new HorizontalFieldManager();
hfield1.add(cityField);
hfield1.add(tempField);
HorizontalFieldManager hfield2 = new HorizontalFieldManager();
hfield2.add(bitmapField);
hfield2.add(condField);
vfield.add(hfield1);
vfield.add(hfield2);
}
The IllegalArgumentException could be unrelated, but nothing is showing up on your screen because you didn't add anything to your screen.
You need to add the vfield to the screen itself. Add the following line:
add(vfield);
Related
I am trying to create a LabelField with no background at all, as a transparent one. I have a background set to my screen with a bitmap and I would like to have my LabelField transparent.
I have the following code but it does not work.
BitmapField info;
EncodedImage logoBitmap = EncodedImage.getEncodedImageResource("userInfo.png");
info = new BitmapField(null, Field.FIELD_LEFT |Field.FIELD_BOTTOM);
info.setImage(logoBitmap);
AbsoluteFieldManager superMainContainer;
superMainContainer.add(info,0,200);
LabelField nameLabel = new LabelField("Name:");
nameLabel.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
superMainContainer.add(nameLabel, 10, 210);
[Updated]
Following code snippet is working on my simulator. Difference between the following one and your code is only some initialization code.
Bitmap bm = Bitmap.getBitmapResource("image.png");
BitmapField info = new BitmapField(bm, Field.FIELD_LEFT
| Field.FIELD_BOTTOM);
LabelField lbl = new LabelField("LabelField Text");
lbl.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
AbsoluteFieldManager superMainContainer = new AbsoluteFieldManager();
superMainContainer.add(info, 0, 200);
superMainContainer.add(lbl, 10, 210);
MainScreen screen = new MainScreen();
screen.add(superMainContainer);
UiApplication.getUiApplication().pushScreen(screen);
[Old]
LabelField lbl;
lbl.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
You didn't initialize the LabelField - nameLabel before applying Background.
And you don't need to set any Background instance for getting a transparent background, the default LabelField will work for this case.
I want to create a popup screen in BlackBerry like the screen appear on long click (see the picture)
My screen contain 3 items
image description
image description
image description
Can any one help me by an example or link to do this popup?
Use the below code and call the GetPopup wherever you want to show the pop up screen
final class Getpopup extends PopupScreen
{
EditField edf;
AutoTextEditField edf1;
HorizontalFieldManager hfm;
public Getpopup()
{
super( new VerticalFieldManager());
LabelField lf = new LabelField("Contact Info", LabelField.FIELD_HCENTER);
SeparatorField sf = new SeparatorField();
edf1= new AutoTextEditField("Name:","" ,20,EditField.NO_NEWLINE);
edf = new EditField("Number:",ThirdScreen.get3);
edf.setEditable(false);
VerticalFieldManager vfm =new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
hfm=new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
ButtonField bf1 = new ButtonField("Save", ButtonField.FIELD_HCENTER);
ButtonField bf2 = new ButtonField("Cancel", ButtonField.FIELD_HCENTER);
hfm.add(bf1);
hfm.add(bf2);
vfm.add(lf);
vfm.add(sf);
vfm.add(edf1);
vfm.add(edf);
vfm.add(hfm);
add(vfm);
}
}
Find the code here to create creating-borderless-transparent-popup screen in blackberry
If your looking for custmizing the Buttons as appeared in image then visit custom-image-buttonfield-in-blackberry
You have to make use of GridFieldManager.java for the layout you have used, Also you can customize your own layout.
Create a PopupDialog class which extends Dialog and then in the constructor, add the Buttons. If you would like your buttons to look like the above image, extend a field or button field and in paint method, draw the button and then the button text below the button. Add this custom button control in the PopupDialog.
I need to align a CheckboxField to the right of a fixed text (on Blackberry) like the "manage connections" dialog.
The code is:
final HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
hfm.add(new LabelField("Test me please", LabelField.ELLIPSIS | FIELD_LEFT | FIELD_VCENTER | USE_ALL_WIDTH));
cbx = new CheckboxField(null, false, FIELD_RIGHT | CheckboxField.NO_USE_ALL_WIDTH);
hfm.add(cbx);
I tried various combinations of "USE_ALL_WIDTH", "NO_USE_ALL_WIDTH" and similar flags, but I still can't get what I want: text all the way to the left, and check box all the way to the right.
If the label is set to USE_ALL_WIDTH, the checkbox disappears, and if it's not set, the checkbox is displayed near the text (not on the right side of the hfm).
Use following code,this will solve your problem.
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_HEIGHT);
LabelField lblShow = new LabelField("Test me please ", Field.FIELD_LEFT);
CheckboxField cbShow = new CheckboxField("", false, CheckboxField.FIELD_RIGHT );
VerticalFieldManager vfmLeft = new VerticalFieldManager();
VerticalFieldManager vfmRight = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vfmLeft.add(lblShow);
vfmRight.add(cbShow);
hfm.add(vfmLeft);
hfm.add(vfmRight);
add(hfm);
Use This style bit to align checkbox to right.
private static final long checkBoxStyle = 134217728;
add(new CheckboxField("test " , false, checkBoxStyle | USE_ALL_WIDTH));
I'm just learing how to program the blackberry and trying to display a bitmap on the screen, here is the code:
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle2");
LabelField lb = new LabelField("hello ted2");
add(lb);
Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png");
BitmapField fd= new BitmapField(logoBitmap, Field.FIELD_HCENTER);
add(fd);
}
The label is drawn but not the bitmap.
Your path is wrong, copy the image into /res/img. To retrieve that, use the file name only.
Bitmap logoBitmap = Bitmap.getBitmapResource("icon2.png");
I think you need to put the two fields into a VerticalFieldManager:
public MyScreen()
{
VerticalFieldManager vfm = new VerticalFieldManager();
// Set the displayed title of the screen
setTitle("MyTitle2");
LabelField lb = new LabelField("hello ted2");
vfm.add(lb);
Bitmap logoBitmap = Bitmap.getBitmapResource("res/icon2.png");
BitmapField fd= new BitmapField(logoBitmap);
vfm.add(fd);
add(vfm);
}
I want to know how to create VerticalFieldManager and i want to add some components also.
Couple of options:
A basic vertical field manager:
VerticalFieldManager vfm = new VerticalFieldManager();
// add your fields
vfm.add(new LabelField("First Label");
vfm.add(new LabelField("Second Label");
// etc
// then don't forget to add your vertical field manager to your screen
// assuming you're in the screen's constructor:
add(vfm);
The labels will appear top to bottom in the order you add them.
If you're going to add more fields than will fit vertically on a screen, you may want to make your manager scrollable:
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
// the rest is the same as above
You can omit VERTICAL_SCROLLBAR if you don't want to see the up/down arrows.
But finally, if you just want a bunch of fields vertically on a screen, MainScreen by default uses a scrolling VerticalFieldManager as its delegate so you can just add fields directly and get the same effect:
class MyScreen extends MainScreen {
public MyScreen() {
add(new LabelField("Label 1");
add(new LabelField("Label 2");
// etc
}
}
Creation :
VerticalFieldManager vfm = new VerticalFieldManager();
Add different fields to it:
vfm.add(somefield);