Blackberry: invoke constructor for verticalfieldmanager - blackberry

I want to run the constructor of a vertical field manager when used in a mainscreen:
vfm = new VerticalFieldManager(){
protected void VerticalFieldManager(){
System.out.println("Fresh");
}
protected void sublayout(int maxWidth, int maxHeight){
super.sublayout(maxWidth, 420);
setExtent(maxWidth,420);
}
};
Of course, VerticalFieldManager does not work.

You cannot have a constructor in an anonymous class, that's just one of the rules of Java.
If you need to override the VerticalFieldManager constructor you will need to create your own class which extends VerticalFieldManager.

Related

Custom Pop up with no Black background in blackberry

I want to remove the black background in Popup field
i know we use applyTheme method in blackberry to subdue its effect but dunno how to use it
I want to remove the black background and use an image instead .
I have tried this method
protected void applyTheme(Graphics arg0, boolean arg1) {
// TODO Auto-generated method stub
super.applyTheme(arg0, arg1);
}
public class CustomDialogBox extends PopupScreen {
Bitmap mDialogImg=null;
public CustomDialogBox(Bitmap dialogImg) {
super(new VerticalFieldManager(),Field.FOCUSABLE);
this.mDialogImg=dialogImg;
VerticalFieldManager vfm=new VerticalFieldManager() {
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, mDialogImg.getWidth(), mDialogImg.getHeight(), mDialogImg, 0, 0);
};
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(mDialogImg.getWidth(), mDialogImg.getHeight());
super.setExtent(mDialogImg.getWidth(), mDialogImg.getHeight());
}
};
add(vfm);
}
protected void applyTheme() {
}
}
I tried the following program and it works perfectly fine
i added a Bitmap image to a vertical field manager and then
using the method
applyTheme() as follows
protected void applyTheme() {
}
i do get the required results

Label/Name for Bitmap Button Field

Currently I have 4 bitmap buttons in my application. I want to have something like Label/Name for each of the buttons so that whenever someone focus on the particular button, the name appears somewhere on the screen. It could be on top, below the buttons or anywhere will do.
How can I do this? I tried searching for bitmap button field labelling but I found nothing really helpful.
you can put a CustomLabelField below button fields. Override your ButtonFields onFocus(int direction) and onUnfocus() methods. Inside them invoke setLabel(String label) method of your CustomLabelField
class CustomLabelField extends Field {
String label;
public void setLabel(String label){
this.label = label;
invalidate();
}
protected void layout(int arg0, int arg1) {
setExtent(Display.getWidth, getFont().getHeight());
}
protected void paint(Graphics graphics) {
graphics.setColor(Color.Black);
graphics.drawText(label, 0, 0);
}
}
EDIT (after comments)
You can use this custom button and add your additional features in it. I did not try if this is working, but should work.
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;
public class CustomButtonField extends BitmapField{
private String label = "";
private MainScreen yourScreen;
public CustomButtonField(String label, MainScreen yourScreen) {
super();
this.label = label;
this.yourScreen = yourScreen;
}
protected void onFocus(int direction) {
yourScreen.setTitle(label);
super.onFocus(direction);
}
protected void onUnfocus() {
yourScreen.setTitle("");
super.onUnfocus();
}
}

Blackberry scoll only browserfield, not entire app-layout

I have a verticalfieldmanager with buttons and below that a browserfield. The problem is that when I scroll vertically in the browserfield the whole layout of the app scrolls with it(!).. I've been looking like a mad man for a sollution but haven't found anything yet. I tried disabling vertical scroll in the app but this only results in not being able to scroll the browserfield/homepage.
Any suggestions?
Thanks
Hope this code helps you: try this;
public class NewsBrowserScreen extends MainScreen implements FieldChangeListener
{
String url="http://www.google.com/news/";
VerticalFieldManager vertical;
BrowserField browserField;
ButtonField click;
public NewsBrowserScreen()
{
createGUI();
}
private void createGUI()
{
click=new ButtonField("Click",Field.FIELD_HCENTER);
click.setChangeListener(this);
add(click);
vertical=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR|HORIZONTAL_SCROLL|HORIZONTAL_SCROLLBAR)
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),250);
setExtent(Display.getWidth(),250);
}
};
vertical.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
vertical.setPadding(10, 0, 10, 0);
add(vertical);
}
protected boolean onSavePrompt()
{
return true;
}
public boolean onMenu(int instance)
{
return true;
}
public void fieldChanged(Field field, int context)
{
if(field==click)
{
browserField=new BrowserField();
vertical.add(browserField);
browserField.requestContent(url);
}
}
}
I Get like this below Image;
You can add a VerticalFieldManager to your MainScreen and add your BrowserField to your VerticalFieldManager. You should set style of VerticalFieldManager with VERTICAL_SCROLL | VERTICAL_SCROLLBAR and clear the syle of your MainScreen

How can i create a popup for custom Choicefield and call it?

I have created my own simple ChoiceField by extending ObjectChoiceField.. It is like..
public class MyChoiceField extends ObjectChoiceField
{
public MyChoiceField(String label ,Object[] choices)
{
super(label, choices);
}
protected void layout(int width, int height)
{
setMinimalWidth(width/2-62);
super.layout(width, height);
}
public void paint(Graphics graphics)
{
super.paint(graphics);
}
}
Now i want to display the my choices when i select MyChoiceField in custom menu(not the default popup that blackberry provides when user clicks on a ChoiceField)..
How can i achieve it? Sample codes will be appreciable..
Thanks
Try Overriding the method fieldChangeNotify(int context) of ObjectChoiceField like this:
public class MyChoiceField extends ObjectChoiceField
{
public MyChoiceField(String label ,Object[] choices)
{
super(label, choices);
}
protected void layout(int width, int height)
{
setMinimalWidth(width/2-62);
super.layout(width, height);
}
protected void fieldChangeNotify(int context) {
int index = getSelectedIndex();
try{
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(new LabelField("[Pop Up Content]\nChoice Field Changed #\n"+choices[index]+" selected."));
PopupScreen popUpScreen = new PopupScreen(vfm){
public boolean onClose()
{
this.close();
return true;
}
};
UiApplication.getUiApplication().pushScreen(popUpScreen);
} catch(Exception exc) {
System.out.println("Exception in choiceField fieldChangeNotify");
}
}
public void paint(Graphics graphics)
{
super.paint(graphics);
}
}
Use MyChoiceField now somewhat like this:
String[] choices; // Keep This Global
VerticalFieldManager vfm = new VerticalFieldManager(Manager.FIELD_VCENTER);
choices = new String[2];
choices[0] = new String("Choice1");
choices[1] = new String("Choice2");
vfm.add(new MyChoiceField("Choise", choices));
Let me know whether this solution works.

Adding fields to a BlackBerry PopupScreen

I want to add fields and buttons to a BlackBerry PopupScreen.
You want customize the popup screen like this
public class CustomPopUpScreen extends PopupScreen {
public CustomPopUpScreen() {
super(new VerticalFieldManager(CustomPopUpScreen.NO_HORIZONTAL_SCROLL));
add(new ButtonField());
add(new ButtonField());
}
}
This code will help you
Here I create object of type PopupScreen and call the method givePopup:
PopupScreen popup1=givePopup();
PopupScreen givePopup(){
VerticalFieldManager popvfm =new VerticalFieldManager();
ButtonField ok=new ButtonField("ok");
ButtonField cancel=new ButtonField("cancel");
popvfm.add(ok);
popvfm.add(cancel);
PopupScreen popup=new PopupScreen(popvfm);
return popup;
}
This method returns a PopupScreen instance that has one vertical field manager and I add two button field on this manager.
public class FriendPopupScreen extends MainScreen{
int dialogWidth;
int dialogHeight;
LabelField lblTitle;
HorizontalFieldManager hfmTitle;
Vector data;
public FriendPopupScreen() {
dialogWidth = 300;
dialogHeight = 150;
lblTitle = newLabelField("Choose option");
hfmTitle = new HorizontalFieldManager(USE_ALL_WIDTH){
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
maxWidth= Display.getWidth();
maxHeight=40;
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, maxHeight);
}
protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
};
hfmTitle.add(lblTitle);
lblTitle.setMargin(10,0,0,10);
add(hfmTitle);
}
protected void sublayout( int width, int height ) {
setExtent( dialogWidth, dialogHeight );
setPosition( Display.getWidth()/2-(dialogWidth/2), Display.getHeight()/2 - (dialogHeight/2));
layoutDelegate( dialogWidth, dialogHeight );
}
}
and call this:
FriendPopupScreen popup = new FriendPopupScreen();
UiApplication.getUiApplication().pushModalScreen(popup);

Resources