i want to set status bar at the bottom of screen and it should display one button left side and one right side. you can see my Screen at below.
my code is like this..
private void BottomLayout()
{
Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
{
protected void paintBackground(Graphics graphics)
{
graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(topBg1.getWidth(), topBg1.getHeight());
setExtent(topBg1.getWidth(), topBg1.getHeight());
}
};
Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);
btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
hfmbottom.add(btn_prev);
Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);
btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
hfmbottom.add(btn_next);
setStatus(hfmbottom);
}
Thanks in advance.
I am posting you only the status bar panel.
Actually in the HorizontalFieldManager it does create problem.
Therefore found out the following way and it is working. It does add extra code but it works
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
class SampleBottomPanelScreen extends MainScreen {
private HorizontalFieldManager title_bar;
private VerticalFieldManager btn1_manager;
private ButtonField btn1;
private VerticalFieldManager btn2_manager;
private ButtonField btn2;
Bitmap bg_image;
public SampleBottomPanelScreen() {
//bg_image = Bitmap.getBitmapResource("backgroundImage.png");
btn1_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_LEFT) {
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth() / 2;
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
btn2_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_RIGHT | VerticalFieldManager.USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth() / 2;
int displayHeight = Display.getHeight();
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
title_bar = new HorizontalFieldManager(Manager.USE_ALL_WIDTH){
public void paint(Graphics graphics) {
graphics.setBackgroundColor(0x2bb1ff);
graphics.clear();
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight() / 8;
super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};
btn1 = new ButtonField("Submit", ButtonField.LEFT | ButtonField.FIELD_LEFT);
btn2 = new ButtonField("Cancel", ButtonField.RIGHT| ButtonField.FIELD_RIGHT);
btn1_manager.add(btn1);
btn2_manager.add(btn2);
title_bar.add(btn1_manager);
title_bar.add(btn2_manager);
this.add(title_bar);
}
}
try layout manager class
package com.doapps.blackberry.layouts;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
public class LayoutManager extends Manager
{
int n;
public LayoutManager(int n)
{
super(Manager.NO_VERTICAL_SCROLL);
this.n =n;
}
protected void sublayout(int width, int height)
{
if(n==2)
{
Field first = getField(0);
Field second = getField(1);
layoutChild(first, this.getPreferredWidth(), this.getPreferredHeight());
layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
setPositionChild(first,0, getPreferredHeight() -first.getHeight());
setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -first.getHeight());
setExtent(width, height);
}
if(n==1)
{
Field second= getField(0);
layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -second.getHeight());
setExtent(width, height);
}
}
public int getPreferredHeight() {
return 45;
}
public int getPreferredWidth() {
return Display.getWidth();
}
}
I think you need to use GridFieldManager. Rearrange the following code fragment to your needs and play with paddings ...
private HorizontalFieldManager createRightTab () {
HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_RIGHT);
ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_1), button_w, button_h);
button.setFocusListener(this);
hMgr.add(button);
return hMgr;
}
private HorizontalFieldManager createLeftTab () {
HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_LEFT);
ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_2), button_w, button_h);
button.setFocusListener(this);
hMgr.add(button);
return hMgr;
}
public void GridControlScreen() {
int w = net.rim.device.api.system.Display.getWidth();
gridMgr = new GridFieldManager(1, 3, 0);
gridMgr.setColumnProperty(0, GridFieldManager.FIXED_SIZE, (button_w));
gridMgr.setColumnProperty(1, GridFieldManager.FIXED_SIZE, (w-(2*button_w)));
gridMgr.setColumnProperty(2, GridFieldManager.FIXED_SIZE, (button_w));
HorizontalFieldManager hMgr_a = createLeftTab();
HorizontalFieldManager hMgr_center = new HorizontalFieldManager();
HorizontalFieldManager hMgr_b = createRightTab();
gridMgr.add(hMgr_a);
gridMgr.add(hMgr_center);
gridMgr.add(hMgr_b);
add(gridMgr);
}
Hope this can help.
Try this
private void BottomLayout()
{
Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
{
protected void paintBackground(Graphics graphics)
{
graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );
super.paint(graphics);
}
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(topBg1.getWidth(), topBg1.getHeight());
setExtent(topBg1.getWidth(), topBg1.getHeight());
}
};
Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);
btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
hfmbottom.add(btn_prev);
Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);
btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
btn_next.setPadding(0, 0, 0, Display.getWidth()-btn_prev.getWidth()-btn_next.getWidth());
hfmbottom.add(btn_next);
setStatus(hfmbottom);
}
this another way which we can set Field Left and right side.
http://keraisureshvblackberry.blogspot.in/2012/02/there-are-very-common-there-there-are.html
Related
I am developing an app in which I need to display products in an expandable list. So I have tried an example which was given in stackoverflow... So, it is working good, but my problem is the divider that will not wrap (expand) based on content expanding, like in screen ...
as you can see, in the screen the date2 field is not displayed properly ..
for that, is there any scrolling facility or can this expand automatically?
Here is my code
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.Touchscreen;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
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.NullField;
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;
class UiMainscreen extends MainScreen implements FieldChangeListener
{
private CustomListField cu_field[];
private Bitmap image=null;
int size=8;
public UiMainscreen() {
VerticalFieldManager vmanager=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
cu_field=new CustomListField[size];
for(int i=0;i<size;i++){
image=Bitmap.getBitmapResource("sample_"+i+".jpg");
cu_field[i]=new CustomListField("BlackBerry models that had a built-in mobile phone, were the first models that natively ran Java, and transmitted data over the normal 2G cellular network. RIM began to advertise these devices as email-capable mobile phones rather than as 2-way pagers.", image, "jan2011", 100, 100,Color.LIGHTGREEN);
cu_field[i].setChangeListener(this);
vmanager.add(new SeparatorField());
vmanager.add(cu_field[i]);
}
add(vmanager);
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
for(int i=0;i<size;i++){
if(field==cu_field[i]){
final int k=i;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("You click on Item No "+k);
}
});
}
}
}
}
class CustomListField extends HorizontalFieldManager{
private Bitmap scale_image;
private int width=0;
private int height=0;
private int background_color=0;
private BitmapField bitmap_field;
private boolean flag=false;
Bitmap logingBg;
public CustomListField(String title, Bitmap image, String date,int image_width,int image_height,int background_color){
super(NO_HORIZONTAL_SCROLL|USE_ALL_WIDTH);
this.background_color=background_color;
width=image_width;
height=image_width;
if(image!=null){
scale_image=new Bitmap(image_width, image_height);
image.scaleInto(scale_image, Bitmap.FILTER_LANCZOS);
bitmap_field=new BitmapField(scale_image);
flag=false;
bitmap_field.setMargin(5, 5, 5, 5);
add(bitmap_field);
}
VerticalFieldManager vmanager=new VerticalFieldManager(USE_ALL_WIDTH|Field.FIELD_VCENTER){
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(), height);
setExtent(Display.getWidth(), height);
}
};
///////////////////////////////////////////
/* Bitmap logingBg = Bitmap.getBitmapResource("myorderdatebackground.png");
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
HorizontalFieldManager hfm2 = new HorizontalFieldManager(Field.FIELD_HCENTER);
ButtonField btnext = new ButtonField("btn");
CustomButtonField btnSignIn = new CustomButtonField(0, "", logingBg,
logingBg, Field.FOCUSABLE, Color.WHITE);
hfm2.add(btnext);
hfm.add(btnSignIn);
hfm.add(hfm2);
vmanager.add(hfm);*/
logingBg = Bitmap.getBitmapResource("myorderdatebackground.png");
HorizontalFieldManager HFM = new HorizontalFieldManager(USE_ALL_WIDTH) {
public void paint(Graphics g) {
//g.setBackgroundColor(Color.BLUE);
g.clear();
g.drawBitmap(0, 0, Display.getWidth(),
logingBg.getHeight(), logingBg, 0, 0);
super.paint(g);
}
};
HorizontalFieldManager lableRegistHFM = new HorizontalFieldManager(
FIELD_VCENTER);
LabelField RegistrationLbl = new LabelField("My Orders",Field.FIELD_HCENTER);
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font11 = fontFamily[1].getFont(FontFamily.CBTF_FONT, 12);
font11 = fontFamily[1].getFont(Font.BOLD, 18);
RegistrationLbl.setFont(font11);
RegistrationLbl.setMargin(0, 0, 0, (Display.getWidth() / 3));
lableRegistHFM.add(RegistrationLbl);
HFM.add(lableRegistHFM);
vmanager.add(HFM);
/**************************************************************/
LabelField title_lbl=new LabelField("Title: "+title,Field.NON_FOCUSABLE|DrawStyle.ELLIPSIS);
vmanager.add(title_lbl);
LabelField date_lbl=new LabelField("Date: "+date,Field.NON_FOCUSABLE);
vmanager.add(date_lbl);
LabelField date_lbl3=new LabelField("Date2: "+date,Field.NON_FOCUSABLE);
vmanager.add(date_lbl3);
LabelField date_lbl4=new LabelField("Date2: "+date,Field.NON_FOCUSABLE);
vmanager.add(date_lbl4);
Font fon=title_lbl.getFont();
int title_height=fon.getHeight();
Font font=date_lbl.getFont();
int date_height=font.getHeight();
int pad=title_height+date_height;
title_lbl.setPadding((height-pad)/2, 0, 0, 0);
add(vmanager);
add(new NullField(FOCUSABLE));
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(), height);
setExtent(Display.getWidth(), height);
}
protected void paint(Graphics graphics) {
if(flag)
graphics.setBackgroundColor(background_color);
graphics.clear();
super.paint(graphics);
}
protected void onFocus(int direction) {
super.onFocus(direction);
flag=true;
invalidate();
}
protected void onUnfocus() {
invalidate();
flag=false;
}
protected boolean navigationClick(int status, int time) {
if(Touchscreen.isSupported()){
return false;
}else{
fieldChangeNotify(1);
return true;
}
}
protected boolean touchEvent(TouchEvent message)
{
if (TouchEvent.CLICK == message.getEvent())
{
FieldChangeListener listener = getChangeListener();
if (null != listener)
this.setFocus();
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
}
The issue is here:
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(), height);
setExtent(Display.getWidth(), height);
}
You're giving manager height less that it needs for content (only image_width).
Also here is possible error:
width=image_width;
height=image_width;
You should use image_height for the height.
And sure you could use scrolling for VerticalManager - add style VERTICAL_SCROLL to constructor. But as user I will find the User Experience (UX) strange in this case.
I am creating a map app. in which i am using mapfield. on the MapFieldScreen I am trying to add Title and also creating tabs but these two things are not visible. instead there is just gray color on these two places..
Here is my code.
class MapFieldScreen extends MainScreen
{
MapFieldScreen()
{
title= new LabelField("My Trip",LabelField.FIELD_HCENTER|LabelField.USE_ALL_WIDTH)
{
protected void layout(int width,int height)
{
setExtent(UIConstants.SCREEN_WIDTH, getFont().getHeight()*2);
}
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawText(label,UIConstants.SCREEN_WIDTH*2/5,getFont().getHeight()/2);
super.paint(g);
}
};
setTitle(title);
mLoc= Bitmap.getBitmapResource(UIConstants.STOP);
mmMapField = new MapField();
add(mMapField);
}
}
You can check follwing code:
LabelField title = new LabelField("My Trip") {
int _width = Display.getWidth();
int _height = getFont().getHeight() * 2;
protected void layout(int width, int height) {
setExtent(_width, _height);
}
public void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
int xText = (_width - getFont().getAdvance(getText())) / 2;
int yText = (_height - getFont().getHeight()) / 2;
graphics.drawText(getText(), xText, yText);
}
};
setTitle(title);
I am new to blackberry,This is my first question.I am doing one sample app for this i require multi line textbox.i googled about this,I found the code below.
VerticalFieldManager vfm =new VerticalFieldManager(Manager.VERTICAL_SCROLL)
{
public void paint(Graphics g)
{
g.drawRoundRect(0, 0,getWidth(), getHeight(),12,12);
super.paint(g);
}
public void sublayout(int width, int height)
{
if (managerWidth == 0) {
managerWidth = width;
}
if (managerHeight == 0) {
managerHeight = height;
}
super.sublayout(managerWidth, managerHeight);
setExtent(managerWidth,managerHeight);
}
};
editField = new EditField(){
public void paint(Graphics g) {
getManager().invalidate();
super.paint(g);
}
};
vfm.add(editField);
vfm.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
add(vfm);
It works fine,if the text is less than Field height,if the text is greater than the field height.The text is crossing the border.How i fix that problem.Please help me.
You need to implement your own custom field.
Documentation can be found here: "Create a custom field"
You can use EditField from Blackberry APIs and use:
yourEditField.setBorder(yourBorder);
You will have then an edit field with a border and which accepts several lines
package nativeapp;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class LoginScreen extends MainScreen {
/**
* Login page
*/
private ButtonField btnLogin;
//private EditField txtUserID;
CustomTextBox txtUserID;
CustomTextBox txtPassword;
// private PasswordEditField txtPassword;
private CheckboxField Chkbox;
private LabelField RememberMe;
public LoginScreen() {
super(NO_VERTICAL_SCROLL);
txtUserID = new CustomTextBox() {
protected void paint(Graphics g) {
// Border roundedBorder = BorderFactory
// .createRoundedBorder(new XYEdges(9, 9, 9, 9),
// Color.GRAY, Border.STYLE_SOLID);
// setBorder(roundedBorder);
// setBackground(BackgroundFactory
// .createSolidBackground(Color.WHITE));
if (getText().length() == 0) {
g.setColor(Color.GRAY);
g.drawText("UserName", 0, 0);
}
g.setColor(Color.BLACK);
//g.drawRect(0, 0, (int) (Display.getWidth() / 1.5),
//txtUserID.getHeight()/* (int)(Display.getHeight()/9) */);
super.paint(g);
}
};
txtPassword = new CustomTextBox() {
protected void paint(Graphics g) {
Border roundedBorder = BorderFactory
.createRoundedBorder(new XYEdges(9, 9, 9, 9),
Color.GRAY, Border.STYLE_SOLID);
setBorder(roundedBorder);
setBackground(BackgroundFactory
.createSolidBackground(Color.WHITE));
if (getText().length() == 0) {
g.setColor(Color.GRAY);
g.drawText("txtPassword", 0, 0);
}
g.setColor(Color.BLACK);
super.paint(g);
}
};
// btnLogin = new ButtonField("SignIn");
btnLogin = new ButtonField("Sign In", Field.FIELD_HCENTER);
Chkbox = new CheckboxField();
// Chkbox.setMargin(0, 0, 0, 30);
RememberMe = new LabelField("Remember Me");
// RememberMe.setMargin(10, 0, 0, 0);
FieldChangeListener login = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String uname = txtUserID.getText().toString().trim();
String pword = txtPassword.getText().toString().trim();
if (!uname.equalsIgnoreCase("")
&& !uname.equalsIgnoreCase(null)
&& !pword.equalsIgnoreCase("")
&& !pword.equalsIgnoreCase(null)) {
boolean lgnStatus = (new httpClient()).loginStatus(uname,
pword, DataURL.smartURLloginchk);
if (lgnStatus) {
PersistentsStore ps = new PersistentsStore();
ps.setObject(DataURL.UserName, uname);
ps.setObject(DataURL.PassWord, pword);
UiApplication.getUiApplication().popScreen(
LoginScreen.this);
UiApplication.getUiApplication().pushScreen(
new WelcomeScreen());
} else {
Dialog.inform("Invalid UserID or Password");
}
} else {
Dialog.inform("UserID and Password shouldnot be Empty");
}
}
};
FieldChangeListener cancel = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
}
};
btnLogin.setChangeListener(login);
// btnCancel.setChangeListener(cancel);
setLoginScreen();
}
private void setLoginScreen() {
VerticalFieldManager vfmForCenterDisplay = new VerticalFieldManager(
Field.FIELD_HCENTER | Field.FIELD_VCENTER | Field.USE_ALL_WIDTH
| Field.USE_ALL_HEIGHT) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(maxWidth, maxHeight);
}
};
Background background = BackgroundFactory.createBitmapBackground(Bitmap
.getBitmapResource("bground.png"));
vfmForCenterDisplay.setBackground(background);
int topSpace = (Display.getHeight() / 4);
vfmForCenterDisplay.setPadding(topSpace, 0, 0, 0);
VerticalFieldManager vfmBasicInfoWithBorder1 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
}
};
BitmapField bitmapField = new BitmapField(
Bitmap.getBitmapResource("loginbg_01.png")) {
protected void layout(int width, int height) {
setExtent(250, 95);
}
};
vfmBasicInfoWithBorder1.add(bitmapField);
VerticalFieldManager vfmBasicInfoWithBorder2 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
}
};
vfmBasicInfoWithBorder2.setBackground(BackgroundFactory
.createBitmapBackground(Bitmap
.getBitmapResource("loginbg_02.jpg")));
VerticalFieldManager vfmBasicInfoWithBorder3 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
setExtent(250, 95);
}
};
vfmBasicInfoWithBorder3.setBackground(BackgroundFactory
.createBitmapBackground(Bitmap
.getBitmapResource("loginbg_03.png")));
vfmBasicInfoWithBorder3.add(btnLogin);
// btnLogin.setMargin(0, 0, 0, 0);
// HorizontalFieldManager hfm1 = new HorizontalFieldManager(
// Field.FIELD_HCENTER);
HorizontalFieldManager hfm2 = new HorizontalFieldManager(
Field.FIELD_VCENTER);
hfm2.add(txtUserID);
// txtUserID.setMargin(0, 0, 0, 0);
HorizontalFieldManager hfm3 = new HorizontalFieldManager(FIELD_HCENTER
& FIELD_VCENTER);
hfm3.add(txtPassword);
// txtPassword.setMargin(0, 0, 0, 10);
HorizontalFieldManager hfm4 = new HorizontalFieldManager(
Field.FIELD_HCENTER);
hfm4.add(Chkbox);
Chkbox.setMargin(0, 0, 0, 10);
hfm4.add(RememberMe);
RememberMe.setMargin(0, 0, 0, 10);
// HorizontalFieldManager hfm5 = new
// HorizontalFieldManager(FIELD_HCENTER
// & FIELD_VCENTER) {
// protected void sublayout(int maxWidth, int maxHeight) {
// super.sublayout(250, 95);
// }
// };
// hfm5.add(btnLogin);
// btnLogin.setMargin(0, 0, 0, 0);
// hfm5.add(btnCancel);
// hfm5.setPadding(new XYEdges(0, 0, 0, ((250 - (70 + 75)) / 2)));
// btnCancel.setMargin(0, 0, 0, 15);
// vfmBasicInfoWithBorder1.add(hfm1);
vfmBasicInfoWithBorder2.add(hfm2);
vfmBasicInfoWithBorder2.add(hfm3);
vfmBasicInfoWithBorder3.add(hfm4);
// vfmBasicInfoWithBorder3.add(hfm5);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder1);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder2);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder3);
add(vfmForCenterDisplay);
}
}
In Blackberry I want to create a class that extends HorizontalFieldManager so that I can display a label and an image on the same line with the label to the left and the image to the right.
I want the user to be able to interact with the HorizontalFieldManager as if it were a single field. I also want each HorizontalFieldManager to be focusable when added to a VeriticalFieldManager. I also want the clcik action events.
Sounds like you'll be wanting to start writing your own Field classes, here's an example to get you started:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class SimpleField extends Field {
private String label;
private Bitmap image;
private int fieldWidth;
private int fieldHeight;
private boolean hover = false;
private int focusColor = 0xcccccc;
public SimpleField(String label, Bitmap image) {
super(Field.FOCUSABLE);
this.label = label;
this.image = image;
fieldWidth = Display.getWidth();
fieldHeight = image.getHeight();
}
protected void onFocus(int direction) {
hover = true;
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
hover = false;
invalidate();
super.onUnfocus();
}
public int getPreferredWidth() {
return fieldWidth;
}
public int getPreferredHeight() {
return fieldHeight;
}
protected void layout(int width, int height) {
setExtent(fieldWidth, fieldHeight);
}
protected void paint(Graphics graphics) {
if(hover){
graphics.setColor(focusColor);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
}
graphics.drawText(label, 0, (fieldHeight - graphics.getFont().getHeight()) / 2);
graphics.drawBitmap(graphics.getFont().getAdvance(label), 0, image.getWidth(), image.getHeight(), image, 0, 0);
}
}
I am trying to change the width and height of a BlackBerry BasicEditField.
But its not displaying the BasicEditField as i mention.
HorizontalFieldManager HFMreg =
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 registration background image
graphics.drawBitmap(0,0,Display.getWidth(),Display.getHeight(),BMregbg, 0, 0);
super.paint(graphics);
}
};
BEFfirstname = new BasicEditField("","",5,EditField.NO_NEWLINE) {
protected void paint(Graphics graphics) {
graphics.fillRect(0,0,80,25);
graphics.setBackgroundColor(Color.WHITE);
graphics.clear();
super.paint(graphics);
}
protected void layout() {
super.layout(getPreferredWidth(),getPreferredHeight());
setExtent(80,25); //width,height
}
public int getPreferredWidth() {
int fieldWidth = 80; //required width
return fieldWidth;
}
public int getPreferredHeight() {
int fieldHeight = 25; // required height
return fieldHeight;
}
};
//BEFfirstname.setMargin(200,0,0,60);
HFMreg.add(LFfirstname);
HFMreg.add(BEFfirstname);
add(HFMreg);
just an other way round:
BasicEditField BEFfirstname = new BasicEditField("","",5,EditField.NO_NEWLINE);
MyManager obj = new MyManger();
obj.add(BEFfirstname);
add(obj);
class MyManager extends Manager
{
MyManager()
{
super(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
}
protected void sublayout(int width, int height)
{
Field f = getField(0);
layoutChild(f,80,25);
setPositionChild(f, 10, 10);
}
}