how to rotate VerticalfieldManager at 180 degrees in blackberry? - blackberry

vf=new VerticalFieldManager()
{
public void paint(Graphics graphics)
{
int theta = Fixed32.toFP(180);
int cell_11 = Fixed32.cosd(theta);
int cell_12 = -Fixed32.sind(theta);
int cell_21 = Fixed32.sind(theta);
int cell_22 = Fixed32.cosd(theta);
int[] rotate = new int[]
{ cell_11, cell_12,
0, 0,
cell_21, cell_22,
};
super.paint(graphics);
myFont = Font.getDefault().derive(Font.PLAIN, 0,
DrawStyle.HCENTER, Font.BOLD,
0, rotate);
vf.setFont(myFont );
}
};

Related

How to set background image fitable in blackberry application

I have written the following code here the background image is displaying but the image did not cover the full background
private Bitmap background;
int mWidth = Display.getWidth();
int mHeight = Display.getHeight();
public MyScreen()
{
// Set the displayed title of the screen
//backgroundBitmap = Bitmap.getBitmapResource("slidimage.png");
final Bitmap background = Bitmap.getBitmapResource("slidimage.png");
HorizontalFieldManager vfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH) {
public void paint(Graphics g) {
g.drawBitmap(0, 0,mWidth, mHeight, background, 0, 0);
super.paint(g);
}
};
add(vfm);
public static Bitmap resizeBitmap(Bitmap image, int width, int height)
{
int rgb[] = new int[image.getWidth()*image.getHeight()];
image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
Bitmap temp2 = new Bitmap(width, height);
temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
return temp2;
}
You can use the above method to resize the image
just pass the image to be resized and its width and height .
and the function will return the resized image .
where rescale Array is the below method
private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
{
int out[] = new int[x2*y2];
for (int yy = 0; yy < y2; yy++)
{
int dy = yy * y / y2;
for (int xx = 0; xx < x2; xx++)
{
int dx = xx * x / x2;
out[(x2 * yy) + xx] = ini[(x * dy) + dx];
}
}
return out;
}

How to set different row height in listfield with implementing listfieldcallback()?

This is my latest Custom_Listfield class.
public class Custom_ListField extends ListField {
private String[] title, category, date, imagepath;
private int[] newsid, catsid;
private List_News newslist;
private Bitmap imagebitmap[], localimage = Config_GlobalFunction
.Bitmap("image_base.png");
private BrowserField webpage;
private boolean islatest;
private int highest = 0;
private Vector content = null;
private ListCallback callback = null;
private int currentPosition = 0;
public Custom_ListField(Vector content, boolean islatest) {
this.content = content;
this.islatest = islatest;
newsid = new int[content.size()];
title = new String[content.size()];
category = new String[content.size()];
date = new String[content.size()];
imagepath = new String[content.size()];
catsid = new int[content.size()];
imagebitmap = new Bitmap[content.size()];
for (int i = 0; i < content.size(); i++) {
newslist = (List_News) content.elementAt(i);
newsid[i] = newslist.getID();
title[i] = newslist.getNtitle();
category[i] = newslist.getNewCatName();
date[i] = newslist.getNArticalD();
imagepath[i] = newslist.getImagePath();
catsid[i] = newslist.getCatID();
if (!imagepath[i].toString().equals("no picture")) {
imagebitmap[i] = Util_ImageLoader.loadImage(imagepath[i]);
if (imagebitmap[i].getHeight() > highest)
highest = imagebitmap[i].getHeight();
} else {
imagebitmap[i] = localimage;
}
catsid[i] = newslist.getCatID();
if (catsid[0] != 9)
this.setRowHeight( localimage.getHeight() + 10);
else
this.setRowHeight( highest + 10);
}
initCallbackListening();
}
private void initCallbackListening() {
callback = new ListCallback();
this.setCallback(callback);
}
private class ListCallback implements ListFieldCallback {
public ListCallback() {
setBackground(Config_GlobalFunction
.loadbackground("background.png"));
}
public void drawListRow(ListField listField, Graphics graphics,
int index, int y, int width) {
currentPosition = index;
graphics.setColor(Color.WHITE);
if (catsid[0] != 9) {
graphics.drawBitmap(
Display.getWidth() - localimage.getWidth() - 5,
y
+ ((listField.getRowHeight() - localimage
.getHeight()) / 2),
localimage.getWidth(), localimage.getHeight(),
imagebitmap[index], 0, 0);
} else {
graphics.drawBitmap(
Display.getWidth() - imagebitmap[index].getWidth() - 5,
y
+ (listField.getRowHeight() - imagebitmap[index]
.getHeight()) / 2,
imagebitmap[index].getWidth(),
imagebitmap[index].getHeight(), imagebitmap[index], 0,
0);
}
graphics.drawRect(0, y, width, listField.getRowHeight());
graphics.setColor(Color.BLACK);
Vector text = Config_GlobalFunction.wrap(title[index],
Display.getWidth() - imagebitmap[index].getWidth() - 10);
for (int i = 0; i < text.size(); i++) {
int liney = y + (i * Font.getDefault().getHeight());
graphics.drawText((String) text.elementAt(i), 5, liney + 3,
DrawStyle.TOP | DrawStyle.LEFT | DrawStyle.ELLIPSIS,
Display.getWidth() - imagebitmap[index].getWidth() - 10);
}
graphics.setColor(Color.GRAY);
graphics.drawText(date[index], 5, y + Font.getDefault().getHeight()
* text.size());
if (islatest) {
graphics.setColor(Color.RED);
graphics.drawText(category[index], Font.getDefault()
.getAdvance(date[index]) + 15, y
+ Font.getDefault().getHeight() * text.size());
}
}
public Object get(ListField listField, int index) {
return content.elementAt(index);
}
public int getPreferredWidth(ListField listField) {
return Display.getWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return content.indexOf(prefix, start);
}
}
public int getCurrentPosition() {
return currentPosition;
}
protected boolean navigationClick(int status, int time) {
final int index = getCurrentPosition();
Main.getUiApplication().pushScreen(new Custom_LoadingScreen(1));
Main.getUiApplication().invokeLater(new Runnable() {
public void run() {
if (catsid[index] == 9) {
if (Config_GlobalFunction.isConnected()) {
webpage = new BrowserField();
MainScreen aboutus = new Menu_Aboutus();
aboutus.add(webpage);
Main.getUiApplication().pushScreen(aboutus);
webpage.requestContent("http://www.orientaldaily.com.my/index.php?option=com_k2&view=item&id="
+ newsid[index] + ":&Itemid=223");
} else
Config_GlobalFunction.Message(
Config_GlobalFunction.nowifi, 1);
} else
Main.getUiApplication().pushScreen(
new Main_NewsDetail(newsid[index]));
}
}, 1 * 1000, false);
return true;
}
}
I tried set with this.setRowHeight(i, highest + 10);. It return wrong size of height and still every row same height.
I believe there was some tricky part and blackberry does not support for set different row height.
To set dynamic row height, it must call again in listfieldcallback()
public class Custom_ListField extends ListField {
private String[] title, category, date, imagepath;
private int[] newsid, catsid;
private List_News newslist;
private Bitmap imagebitmap[], localimage = Config_GlobalFunction
.Bitmap("image_base.png");
private BrowserField webpage;
private boolean islatest;
private Vector content = null, text;
private ListCallback callback = null;
private int currentPosition = 0;
public Custom_ListField(Vector content, boolean islatest) {
this.content = content;
this.islatest = islatest;
newsid = new int[content.size()];
title = new String[content.size()];
category = new String[content.size()];
date = new String[content.size()];
imagepath = new String[content.size()];
catsid = new int[content.size()];
imagebitmap = new Bitmap[content.size()];
for (int i = 0; i < content.size(); i++) {
newslist = (List_News) content.elementAt(i);
newsid[i] = newslist.getID();
title[i] = newslist.getNtitle();
category[i] = newslist.getNewCatName();
date[i] = newslist.getNArticalD();
imagepath[i] = newslist.getImagePath();
catsid[i] = newslist.getCatID();
if (!imagepath[i].toString().equals("no picture")) {
imagebitmap[i] = Util_ImageLoader.loadImage(imagepath[i]);
}
}
initCallbackListening();
}
private void initCallbackListening() {
callback = new ListCallback();
this.setCallback(callback);
this.setRowHeight(-2);
}
private class ListCallback implements ListFieldCallback {
public ListCallback() {
}
public void drawListRow(ListField listField, Graphics graphics,
int index, int y, int width) {
currentPosition = index;
setBackground(BackgroundFactory.createBitmapBackground(
Bitmap.getBitmapResource("background_news_list.png"),
Background.POSITION_X_LEFT, Background.POSITION_Y_TOP,
Background.REPEAT_SCALE_TO_FIT));
if (!imagepath[index].toString().equals("no picture")) {
float ratio = (float) ((float) localimage.getHeight() / (float) imagebitmap[index]
.getHeight());
Bitmap temp = new Bitmap(
(int) (imagebitmap[index].getWidth() * ratio),
(int) (imagebitmap[index].getHeight() * ratio));
imagebitmap[index].scaleInto(temp, Bitmap.FILTER_BILINEAR,
Bitmap.SCALE_TO_FIT);
imagebitmap[index] = temp;
graphics.drawBitmap(
Display.getWidth()
- localimage.getWidth()
- 5
+ ((localimage.getWidth() - imagebitmap[index]
.getWidth()) / 2),
y
+ (listField.getRowHeight(index) - localimage
.getHeight()) / 2,
imagebitmap[index].getWidth(),
imagebitmap[index].getHeight(), imagebitmap[index], 0,
0);
graphics.setColor(Color.BLACK);
text = Config_GlobalFunction
.wrap(title[index], Display.getWidth()
- imagebitmap[index].getWidth() - 10);
for (int i = 0; i < text.size(); i++) {
int liney = y + (i * Font.getDefault().getHeight());
graphics.drawText(
(String) text.elementAt(i),
5,
liney + 3,
DrawStyle.TOP | DrawStyle.LEFT | DrawStyle.ELLIPSIS,
Display.getWidth() - imagebitmap[index].getWidth()
- 10);
}
} else {
graphics.setColor(Color.BLACK);
text = Config_GlobalFunction.wrap(title[index],
Display.getWidth() - 10);
for (int i = 0; i < text.size(); i++) {
int liney = y + (i * Font.getDefault().getHeight());
graphics.drawText(
(String) text.elementAt(i),
5,
liney + 3,
DrawStyle.TOP | DrawStyle.LEFT | DrawStyle.ELLIPSIS,
Display.getWidth() - 10);
}
}
if (text.size() == 2) {
graphics.setColor(Color.GRAY);
graphics.drawText(date[index], 5, y
+ Font.getDefault().getHeight() + 3);
if (islatest) {
graphics.setColor(Color.RED);
graphics.drawText(category[index], Font.getDefault()
.getAdvance(date[index]) + 15, y
+ Font.getDefault().getHeight() + 3);
}
} else if (text.size() == 3) {
graphics.setColor(Color.GRAY);
graphics.drawText(date[index], 5, y
+ Font.getDefault().getHeight() * 2 + 3);
if (islatest) {
graphics.setColor(Color.RED);
graphics.drawText(category[index], Font.getDefault()
.getAdvance(date[index]) + 15, y
+ Font.getDefault().getHeight() * 2 + 3);
}
}
if (!imagepath[index].toString().equals("no picture")) {
setRowHeight(index, imagebitmap[index].getHeight() + 10);
} else {
if (text.size() == 2)
setRowHeight(index, getRowHeight() + 9);
else if (text.size() == 3) {
setRowHeight(index, getRowHeight() * 15 / 10 + 9);
}
}
graphics.setColor(Color.WHITE);
graphics.drawRect(0, y, width, listField.getRowHeight(index));
}
public Object get(ListField listField, int index) {
return content.elementAt(index);
}
public int getPreferredWidth(ListField listField) {
return Display.getWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return content.indexOf(prefix, start);
}
}
public int getCurrentPosition() {
return currentPosition;
}
protected boolean navigationClick(int status, int time) {
final int index = getCurrentPosition();
Main.getUiApplication().pushScreen(new Custom_LoadingScreen(1));
Main.getUiApplication().invokeLater(new Runnable() {
public void run() {
if (catsid[index] == 9) {
if (Config_GlobalFunction.isConnected()) {
webpage = new BrowserField();
MainScreen aboutus = new Menu_Aboutus();
aboutus.add(webpage);
Main.getUiApplication().pushScreen(aboutus);
webpage.requestContent("http://www.orientaldaily.com.my/index.php?option=com_k2&view=item&id="
+ newsid[index] + ":&Itemid=223");
} else
Config_GlobalFunction.Message(
Config_GlobalFunction.nowifi, 1);
} else
Main.getUiApplication().pushScreen(
new Main_NewsDetail(newsid[index]));
}
}, 1 * 1000, false);
return true;
}
}

how to create widget in blackberry?

This is my custom layout which was same as android linear layout
public class Custom_TopField extends VerticalFieldManager {
private static final int FIELD_HEIGHT = 70;
private String _text;
Custom_TopField(int color, String text) {
super(Manager.NO_VERTICAL_SCROLL);
_text = text;
Background background = BackgroundFactory.createSolidBackground(color);
setBackground(background);
}
protected void sublayout(int width, int height) {
width = Math.min(width, getPreferredWidth());
height = Math.min(height, getPreferredHeight());
setExtent(width, height);
}
public int getPreferredHeight() {
return FIELD_HEIGHT;
}
public int getPreferredWidth() {
return Display.getWidth();
}
public void paint(Graphics graphics) {
int rectHeight = getPreferredHeight();
int rectWidth = getPreferredWidth();
Font font = Font.getDefault().derive(Font.BOLD, 65);
graphics.drawRect(0, 0, rectWidth, rectHeight);
graphics.drawText(_text, rectWidth / 2, 10);
graphics.setFont(font);
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
}
Output = background red and font = black
What I want is background red, font white, font size 40.
I also want to know how to create widget programmatically?
To set the font to white and the size to 40 change the paint as follows:
public void paint(Graphics graphics) {
int rectHeight = getPreferredHeight();
int rectWidth = getPreferredWidth();
Font font = Font.getDefault().derive(Font.BOLD, 40);
graphics.setColor(Color.WHITE);
graphics.setFont(font);
graphics.drawRect(0, 0, rectWidth, rectHeight);
graphics.drawText(_text, rectWidth / 2, 10);
super.paint(graphics);
}

ObjectChoiceField width and height issue in BlackBerry?

I am working a UI based application in BlackBerry. UI is like the following:
label-1 : Oject choice field-1
label-2 : Oject choice field-2
label-3 : Oject choice field-3
label-4 : Oject choice field-4
label-5 : Oject choice field-5
It is really getting difficult to generate this UI. The width and height is the main issue for my difficulty.
public HomeScreen() {
super(MainScreen.USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);
_dbOperations = new DBOperations();
_mainVFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
_mainVFM.setMargin(10, 10, 40, 10);
_menuFieldVFM = new VerticalFieldManager();
_menuFieldVFM.setMargin(0, 5, 0, 0);
_menuDropDownVFM = new VerticalFieldManager();
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createSolidBackground(Constants.BgColorCode));
XYEdges padding = new XYEdges(1, 1, 1, 1);
Border roundedBorder = BorderFactory.createSimpleBorder(padding);
// HEADING
_headingHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
_headingLabelField = new LabelField(Constants.Text_heading);
_headingLabelField.setFont(ApplicationFont.labelFont);
_headingHFM.add(_headingLabelField);
_headingHFM.setMargin(0, 0, 20, 0);
// _productLine LINE
_productLineLabelField = new LabelField(Constants.Text_ProductLine);
_productLineLabelField.setFont(ApplicationFont.explainationFont);
_productLineLabelField.setMargin(8, 0, 0, 0);
_menuFieldVFM.add(_productLineLabelField);
int plSetTo1 = 0;
_productLineOCF = new ObjectChoiceField("", _productLineArray, plSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_productLineOCF.setFont(ApplicationFont.explainationFont);
_productLineOCF.setChangeListener(this);
_menuDropDownVFM.add(_productLineOCF);
// HP
_HPLabelField = new LabelField(Constants.Text_HP);
_HPLabelField.setFont(ApplicationFont.explainationFont);
_HPLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_HPLabelField);
int hpSetTo1 = 0;
String data_HP[] = { "Select HP" };
_HP_OCF = new ObjectChoiceField("", data_HP, hpSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_HP_OCF.setFont(ApplicationFont.explainationFont);
_HP_OCF.setChangeListener(this);
_menuDropDownVFM.add(_HP_OCF);
_RPMLabelField = new LabelField(Constants.Text_RPM);
_RPMLabelField.setFont(ApplicationFont.explainationFont);
_RPMLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_RPMLabelField);
int rpmSetTo1 = 0;
String data_RPM[] = { "Select RPM" };
_RPM_OCF = new ObjectChoiceField("", data_RPM, rpmSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_RPM_OCF.setChangeListener(this);
_menuDropDownVFM.add(_RPM_OCF);
// VOLTAGE
_voltageLabelField = new LabelField(Constants.Text_voltage);
_voltageLabelField.setFont(ApplicationFont.explainationFont);
_voltageLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_voltageLabelField);
int volSetTo1 = 0;
String data_voltage[] = { "Select Voltage" };
_voltageOCF = new ObjectChoiceField("", data_voltage, volSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_voltageOCF.setChangeListener(this);
_menuDropDownVFM.add(_voltageOCF);
// FRAME SIZE
_frameSizeLabelField = new LabelField(Constants.Text_frameSize);
_frameSizeLabelField.setFont(ApplicationFont.explainationFont);
_frameSizeLabelField.setMargin(25, 0, 0, 0);
_menuFieldVFM.add(_frameSizeLabelField);
// int iSetTo1 = 0;
_frameSizeOCF = new ObjectChoiceField("", _frameArray, plSetTo1, Field.FIELD_RIGHT) {
protected void layout(int width, int height) {
setMinimalWidth(width - 60);
super.layout(width, height);
};
};
_frameSizeOCF.setChangeListener(this);
_menuDropDownVFM.add(_frameSizeOCF);
_menuMainHFM = new HorizontalFieldManager();
_menuMainHFM.add(_menuFieldVFM);
_menuMainHFM.add(_menuDropDownVFM);
// -OR- LABEL
_orLabelField = new LabelField(Constants.Text_or);
_orLabelField.setMargin(20, 0, 0, 0);
_orLabelField.setFont(ApplicationFont.labelFont);
// SEARCH BY PART NUMBER
_SearchByPartNumberField = new LabelField(Constants.Text_PartNoLabel);
_SearchByPartNumberField.setMargin(20, 0, 0, 0);
_SearchByPartNumberField.setFont(ApplicationFont.labelFont);
// ENTER PART NUMBER
_enterPartNoHFM = new HorizontalFieldManager();
_enterPartNoLabelField = new LabelField("Enter Part Number: ");
_partNumberEditField = new EditField();
_partNumberEditField.setBorder(roundedBorder);
_enterPartNoHFM.add(_enterPartNoLabelField);
_enterPartNoHFM.add(_partNumberEditField);
_enterPartNoHFM.setMargin(20, 0, 0, 0);
// SAERCH BUTTON
_searchButtonField = new ButtonField(" Search ", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_searchButtonField.setChangeListener(this);
_searchButtonField.setMargin(20, 0, 0, 0);
_checkForUpdates = new ButtonField(Constants.Button_checkForUpdates, ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_checkForUpdates.setMargin(10, 0, 0, 0);
_checkForUpdates.setChangeListener(this);
_mainVFM.add(_headingHFM);
_mainVFM.add(_menuMainHFM);
_mainVFM.add(_orLabelField);
_mainVFM.add(_SearchByPartNumberField);
_mainVFM.add(_enterPartNoHFM);
_mainVFM.add(_searchButtonField);
_mainVFM.add(_checkForUpdates);
add(_mainVFM);
}
Now I am using following code. But no progress, I am at the same stage.
public HomeScreen() {
super(MainScreen.USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL);
_dbOperations = new DBOperations();
_mainVFM = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH);
_mainVFM.setMargin(10, 10, 40, 10);
((VerticalFieldManager) getMainManager()).setBackground(BackgroundFactory.createSolidBackground(Constants.BgColorCode));
// HEADING
_headingHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
_headingLabelField = new LabelField(Constants.Text_heading);
_headingLabelField.setFont(ApplicationFont.labelFont);
_headingHFM.add(_headingLabelField);
_headingHFM.setMargin(0, 0, 20, 0);
// IMPORTANT CALCULATION
String productLineString = Constants.Text_ProductLine;
int charWidth = 0;
for (int i = 0; i < productLineString.length(); i++) {
charWidth = Font.getDefault().getAdvance(String.valueOf(productLineString.charAt(i)));
totalWidth += charWidth;
System.out.println(totalWidth + "===>>>>>>total width" + i);
}
System.out.println(totalWidth + "===>>>>>>total width");
totalWidth = totalWidth + 10;
// _productLine LINE
_productLineLabelField = new LabelField(Constants.Text_ProductLine);
_productLineLabelField.setFont(ApplicationFont.explainationFont);
_productLineLabelField.setMargin(8, 0, 0, 0);
int plSetTo1 = 0;
_productLineOCF = new ObjectChoiceField("", _productLineArray, plSetTo1, Field.FIELD_RIGHT);
_productLineOCF.setFont(ApplicationFont.explainationFont);
_productLineOCF.setChangeListener(this);
_productHFM = new HorizontalFieldManager(USE_ALL_WIDTH | FOCUSABLE);
_productHFM.add(_productLineLabelField);
_productHFM.add(_productLineOCF);
// HP
_hp1 = new VerticalFieldManager();
_HPLabelField = new LabelField(Constants.Text_HP);
_HPLabelField.setFont(ApplicationFont.explainationFont);
_HPLabelField.setMargin(25, 0, 0, 0);
_hp1.add(_HPLabelField);
_hp2 = new VerticalFieldManager();
int hpSetTo1 = 0;
String data_HP[] = { " Select HP" };
_HP_OCF = new ObjectChoiceField("", data_HP, hpSetTo1, Field.FIELD_RIGHT | USE_ALL_WIDTH);
_HP_OCF.setMinimalWidth(totalWidth + 50);
_HP_OCF.setFont(ApplicationFont.explainationFont);
_HP_OCF.setChangeListener(this);
_hp2.add(_HP_OCF);
_hpHFM = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(maxWidth, maxHeight);
int x = totalWidth;
setPositionChild(_hp2, x, 0);
}
};
_hpHFM.add(_hp1);
_hpHFM.add(_hp2);
_RPM_HFM = new HorizontalFieldManager();
// RPM
_RPMLabelField = new LabelField(Constants.Text_RPM);
_RPMLabelField.setFont(ApplicationFont.explainationFont);
_RPMLabelField.setMargin(25, 0, 0, 0);
_RPM_HFM.add(_RPMLabelField);
int rpmSetTo1 = 0;
String data_RPM[] = { "Select RPM" };
_RPM_OCF = new ObjectChoiceField("", data_RPM, rpmSetTo1, Field.FIELD_RIGHT);
_RPM_OCF.setMinimalWidth(totalWidth + 50);
_RPM_OCF.setChangeListener(this);
_RPM_HFM.add(_RPM_OCF);
_voltageHFM = new HorizontalFieldManager();
// VOLTAGE
_voltageLabelField = new LabelField(Constants.Text_voltage);
_voltageLabelField.setFont(ApplicationFont.explainationFont);
_voltageLabelField.setMargin(25, 0, 0, 0);
_voltageHFM.add(_voltageLabelField);
int volSetTo1 = 0;
String data_voltage[] = { "Select Voltage" };
_voltageOCF = new ObjectChoiceField("", data_voltage, volSetTo1, Field.FIELD_RIGHT);
_voltageOCF.setMinimalWidth(totalWidth + 50);
_voltageOCF.setChangeListener(this);
_voltageHFM.add(_voltageOCF);
_frameHFM = new HorizontalFieldManager();
// FRAME SIZE
_frameSizeLabelField = new LabelField(Constants.Text_frameSize);
_frameSizeLabelField.setFont(ApplicationFont.explainationFont);
_frameSizeLabelField.setMargin(25, 0, 0, 0);
_frameHFM.add(_frameSizeLabelField);
int fSetTo1 = 0;
_frameSizeOCF = new ObjectChoiceField("", _frameArray, fSetTo1, Field.FIELD_RIGHT);
_frameSizeOCF.setMinimalWidth(totalWidth + 50);
_frameSizeOCF.setChangeListener(this);
_frameHFM.add(_frameSizeOCF);
// -OR- LABEL
_orLabelField = new LabelField(Constants.Text_or);
_orLabelField.setMargin(20, 0, 0, 0);
_orLabelField.setFont(ApplicationFont.labelFont);
// SEARCH BY PART NUMBER
_SearchByPartNumberField = new LabelField(Constants.Text_PartNoLabel);
_SearchByPartNumberField.setMargin(20, 0, 0, 0);
_SearchByPartNumberField.setFont(ApplicationFont.labelFont);
// ENTER PART NUMBER
_enterPartNoHFM = new HorizontalFieldManager();
_enterPartNoLabelField = new LabelField("Enter Part Number: ");
_partNumberEditField = new EditField();
_partNumberEditField.setBorder(roundedBorder);
_enterPartNoHFM.add(_enterPartNoLabelField);
_enterPartNoHFM.add(_partNumberEditField);
_enterPartNoHFM.setMargin(20, 0, 0, 0);
// SAERCH BUTTON
_searchButtonField = new ButtonField(" Search ", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_searchButtonField.setChangeListener(this);
_searchButtonField.setMargin(20, 0, 0, 0);
_checkForUpdates = new ButtonField(Constants.Button_checkForUpdates, ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
_checkForUpdates.setMargin(10, 0, 0, 0);
_checkForUpdates.setChangeListener(this);
add(_pageHeaderHFM);
_mainVFM.add(_headingHFM);
_mainVFM.add(_productHFM);
_mainVFM.add(_hpHFM);
_mainVFM.add(_RPM_HFM);
_mainVFM.add(_voltageHFM);
_mainVFM.add(_frameHFM);
_mainVFM.add(_orLabelField);
_mainVFM.add(_SearchByPartNumberField);
_mainVFM.add(_enterPartNoHFM);
_mainVFM.add(_searchButtonField);
_mainVFM.add(_checkForUpdates);
add(_mainVFM);
}
I am fine with the width of the OCF but height and the position of the OCF must be settled as required. This is the output I am getting with this code.
This answer is based on following links:
Align Field in HorizontalFieldManager.
BlackBerry HorizontalFieldManager alignment.
Try following code:
class HomeScreen extends MainScreen {
public HomeScreen() {
super(Field.USE_ALL_WIDTH | Field.USE_ALL_HEIGHT | MainScreen.VERTICAL_SCROLL);
VerticalFieldManager vfmMain = new VerticalFieldManager(Field.USE_ALL_WIDTH);
// LabelField
LabelField lblFOne = new LabelField("LabelField One", Field.FIELD_LEFT | Field.FIELD_VCENTER);
// ObjectChoiceField
VerticalFieldManager vfmChoiceFieldContainerOne = new VerticalFieldManager(Field.USE_ALL_WIDTH | Field.FIELD_RIGHT);
final String[] options = new String[] { "Choice One - A very long string.", "Choice B", "Choice C" };
ObjectChoiceField ocfOne = new ObjectChoiceField("", options, 0, Field.FIELD_RIGHT | ObjectChoiceField.FORCE_SINGLE_LINE);
vfmChoiceFieldContainerOne.add(ocfOne);
// Contain a row of LabelField and ObjectChoiceField
HorizontalFieldManager hfmRowOne = new HorizontalFieldManager(Field.USE_ALL_WIDTH | Field.FOCUSABLE);
hfmRowOne.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
hfmRowOne.add(lblFOne);
hfmRowOne.add(vfmChoiceFieldContainerOne);
vfmMain.add(hfmRowOne);
add(vfmMain);
}
}

setExtent for nested HorizontalFieldManagers

I am developing an application where I should use nested horizontalmanagers. I am taking inner and outer HFMs. The fields of innerHFM overlap on the outerHFM when I scroll the fields. How can I use setExtent method for innerHFM. My innerHFM contains fields like 1 2 3 4 5 and my outerHFM contains next and previous buttons. Here is the code I implemented
outerHFM = new HorizontalFieldManager() {
protected void sublayout(int maxWidth, int maxHeight) {
layoutChild(next, maxWidth, maxHeight);
setPositionChild(next, 300, 5);
layoutChild(innerHfm, 200, maxHeight);
setPositionChild(innerHfm, 10, 5);
layoutChild(previous, maxWidth, maxHeight);
setPositionChild(previous, 44, 5);
setExtent(maxWidth, 40);
}
};
innerHfm = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL|Manager.USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight) {
int space = 0;
int x = 90;
for (int i = 0; i < cardsSize; i++) {
layoutChild(numbtn[i], 210, maxHeight);
setPositionChild(numbtn[i], x + space+offset, 0);
space = space + 50;
}
setExtent(240, 40);
}
};
Hi this sizing works for all my field managers.
int managerWidth;
int managerHeight;
public int getPreferredWidth() {
return managerWidth;
}
public int getPreferredHeight() {
return managerHeight;
}
public void sublayout(int w, int h) {
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth, managerHeight);
}
maybe that manualy positionig might be problem, you can use AbsoluteFieldManager instead...

Resources