How to create VerticalField Manager in Blackberry? - blackberry

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);

Related

how to improve autosuggest/complete in blackberry + java

I am facing lot of issues while implement the auto suggest :I will tell you my issues .
1) Focus is always comes on auto suggest /complete field.First there is button .But focus is also on autosuggest field as shown in figure
2) When I write m on auto suggest field monday is display when I click the track pad it display monday on autosuggest field But Monday of pop up is not hide.
3) what is this encircle .How to change is gray color (or remove this color).some times it display on whole field and some time on half field
4) I just want a auto suggest with fix width not whole width .Like this on a screen with black background and autosuggest (edit field have white background no gray when focus comes on auto suggest)
Example
Label Auto suggest
Days Auto-complete of days
public final class MyScreen extends MainScreen implements JsonObserver
{
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
// Set the displayed title of the screen
setTitle("Drop-down List Demo");
VerticalFieldManager vfm=new VerticalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, maxHeight/2);
}
protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, Display.getWidth(), Display.getHeight()/2);
super.paint(graphics);
}
};
vfm.add(new ButtonField("add"));
BasicFilteredList filterList = new BasicFilteredList();
String[] days = {"Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday"};
filterList.addDataSet(1,days,"days",BasicFilteredList.COMPARISON_IGNORE_CASE);
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
vfm.add(autoCompleteField);
vfm.add(new ButtonField("addpppp"));
add(vfm);
}
}

Adding background image to blackberry app not working

i am new to blackberry development and want to add an image to a sample blackberry application. I have tried multiple tutorials, but the image is not displaying in the background
can any one kindly tell me what is the problem?
/**
* This class extends the UiApplication class, providing a graphical user
* interface.
*/
public class Diverse extends UiApplication {
private Bitmap backgroundBitmap;
private Bitmap fieldBitmap;
public static void main(String[] args) {
Diverse diverse = new Diverse();
diverse.enterEventDispatcher();
}
/**
* Creates a new MyApp object
*/
public Diverse() {
//The background image.
backgroundBitmap = Bitmap.getBitmapResource("background.png");
MainScreen mainScreen = new MainScreen();
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT){
//Override the paint method to draw the background image.
public void paint(Graphics graphics)
{
//Draw the background image and then call paint.
graphics.drawBitmap(0, 0, 240, 240, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
//The LabelField will show up through the transparent image.
LabelField labelField = new LabelField("This is a label");
//A bitmap field with a transparent image.
//The background image will show up through the transparent BitMapField image.
BitmapField bitmapField = new BitmapField(Bitmap.getBitmapResource("field.png"));
//Add the manager to the screen.
mainScreen.add(horizontalFieldManager);
//Add the fields to the manager.
horizontalFieldManager.add(labelField);
horizontalFieldManager.add(bitmapField);
// Push a screen onto the UI stack for rendering.
pushScreen(new DiverseScreen());
}
}
and DiverseScreen class is
package diverse;
import net.rim.device.api.ui.container.MainScreen;
/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class DiverseScreen extends MainScreen
{
/**
* Creates a new MyScreen object
*/
public DiverseScreen()
{
// Set the displayed title of the screen
setTitle("Diverse");
}
}
The problem is that you have set the background image for one screen, but you never displayed that screen. Then, you displayed a different screen that did not have a background image set.
First, it helps to understand the BlackBerry UI framework. It allows you to create a hierarchy of objects on screen. At the top level, you have a Screen (or subclass of Screen), and then inside of the Screen, you have Managers, and inside them are Fields. But, each level must be added to a container of some kind, and finally, the top-level Screen must be displayed with something like pushScreen().
See a little more description on this hierarchy in a recent answer here
In your situation, you should change this line
MainScreen mainScreen = new MainScreen();
to
DiverseScreen mainScreen = new DiverseScreen();
and then change this line
pushScreen(new DiverseScreen());
to
pushScreen(mainScreen);
since mainScreen is the instance where you added a horizontal field manager that draws your background image.

create popup screen in blackBerry

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.

need help with Field Managers Blackberry

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);

Creating an application information/help screen on Blackberry

I'm trying to create a Help/About screen for my application, but I've discovered that, well, my code sucks. (I know it could use a little refactoring, but when working with a new framework I get the code working first then immediately go back and refactor to do things "properly").
First, what I'm doing doesn't "feel" like the right way of doing it. I'm not sure about just stuffing a bunch of text fields into the layout - is there a better way of doing so?
Second, the VFM is taking up the bulk of the screen and pushing my 'Close' button off the bottom. What I'm trying to do is keep the title and 'Close' button visible but just scroll the VFM.
How can I solve these problems?
public class HelpScreen extends PopupScreen {
public HelpScreen() {
super(new VerticalFieldManager(), Field.FOCUSABLE);
/* Construct the Close button */
FieldChangeListener listener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ok();
}
};
ButtonField b = new ButtonField("Close", Field.FIELD_HCENTER);
b.setChangeListener(listener);
/* Construct the text box containing the help */
VerticalFieldManager vfm = new VerticalFieldManager(VERTICAL_SCROLL);
TextField f;
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
f.setText("My application does stuff. This part is the description of what it does.");
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
f.setText("Commands:");
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
f.setText("N - New Widget");
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
f.setText("R - Rename Widget");
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
f.setText("D - Duplicate Widget");
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
f.setText("C - Clear Widget");
vfm.add(f = new TextField(FIELD_LEFT | READONLY));
f.setText("Shift-Delete - Delete Widget");
/* Construct the screen */
add(new LabelField("About Widget Wiffleball", Field.FIELD_HCENTER));
add(new SeparatorField());
add(vfm);
add(b);
}
public void ok() {
UiApplication.getUiApplication().popScreen(this);
}
}
For the code not 'feeling right' - functionally it seems fine, but a bit of refactoring could clean it up a bit - maybe make a method to create and populate the TextFields
private TextField createTextField(String content) {
TextField textField = new TextField(
}
Then that portion of the constructor becomes:
VerticalFieldManager vfm = new VerticalFieldManager(VERTICAL_SCROLL);
vfm.add(createTextField("My application does stuff. This part is the description of what it does."));
vfm.add(createTextField("Commands:"));
vfm.add(createTextField("N - New Widget"));
vfm.add(createTextField("R - Rename Widget"));
vfm.add(createTextField("D - Duplicate Widget"));
vfm.add(createTextField("C - Clear Widget"));
vfm.add(createTextField("Shift-Delete - Delete Widget"));
You solve the layout problem using a custom field manager - really not difficult, you just have to subclass Manager and implement sublayout. Define a 'top', 'bottom', and 'middle' field, and layout accordingly (some code left out as an exercise to the reader, but basically when adding fields to the manager you'll need to be able to specify one as top and one as bottom. The following logic will make sure the bottom field is always stuck to the bottom, and the top 2 fields don't push it off the bottom:
protected void sublayout(int width, int height) {
// retrieve the top, middle and bottom fields
int heightRemaining = height;
layoutChild(topField, width, heightRemaining);
setPositionChild(topField, 0, 0);
heightRemaining -= topField.getHeight();
layoutChild(bottomField, width, heightRemaining);
setPositionChild(bottomField, 0, height - bottomField.getHeight());
heightRemaining -= bottomField.getHeight();
layoutChild(middleField, width, heightRemaining);
setPositionChild(middleField, 0, topField.getHeight());
}
Again, just a framework - no error checking or anything in there. Then set your delegate to be this new manager, set your vertical field manager to be the middle field (you'll probably want a designated setter), your button field to the bottom field (again, designated getter).

Resources