I am new to blackberry development. I want a Custom Tab bar at the Bottom of the screen for blackberry application in my project, same as the image given below.I tried the sample code given by blackberry.
But now I want to use customised UI.I have searched it on Google and didn't get any productive information on what I want ,for custom fields. Please tell me how to do it in blackberry.
Has anyone done this previously?
Please reply Anything link/code/snippet.
Try this code -
EncodedImage e2 = EncodedImage.getEncodedImageResource("map.png");
EncodedImage e3 = EncodedImage.getEncodedImageResource("members.png");
EncodedImage e4 = EncodedImage.getEncodedImageResource("message.png");
EncodedImage e5 = EncodedImage.getEncodedImageResource("settings.png");
EncodedImage e6 = EncodedImage.getEncodedImageResource("logout.png");
EyelidFieldManager manager = new EyelidFieldManager();
HorizontalFieldManager buttonPanel = new HorizontalFieldManager(Field.FIELD_TOP | Field.USE_ALL_WIDTH);
VerticalFieldManager vfm=new VerticalFieldManager();
vfm.add(new BitmapField(e2.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("MAP");
return true;
}
});
buttonPanel.add(vfm);
buttonPanel.add(new LabelField(" "));
VerticalFieldManager vfm1=new VerticalFieldManager();
vfm1.add(new BitmapField(e3.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Members");
return true;
}
});
buttonPanel.add(vfm1);
VerticalFieldManager vfm2=new VerticalFieldManager();
vfm2.add(new BitmapField(e4.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Message");
return true;
}
});
buttonPanel.add(vfm2);
VerticalFieldManager vfm3=new VerticalFieldManager();
vfm3.add(new BitmapField(e5.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Settings");
return true;
}
});
buttonPanel.add(vfm3);
VerticalFieldManager vfm4=new VerticalFieldManager();
vfm4.add(new BitmapField(e6.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Logout");
return true;
}
});
buttonPanel.add(vfm4);
manager.add(buttonPanel);
setTitle(manager);
you forgot something. create new class within constructor which pushscreen the other class which extends main screen
example:
public class MyApp extends UiApplication{
public MyApp(){
pushScreen(new LoadingScreen());
} }
Related
I want if anyone click a label then it should trigger a function. Like I want if a user clicks a label then it should go to another page. Following is the code I tried.
Thanks in Advance!!
LabelField joinGroups = new LabelField("Join Groups",LabelField.FOCUSABLE ){
protected void layout(int width, int height) {
super.layout(width, height);
this.setExtent(1000, 44);
}
};
FChangeListener customListenerSurveys = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.alert("Surveys Clicked!");
}
};
joinGroups.setFocusListener(customListenerSurveys);
Try Navigation Clack.
LabelField joinGroups = new LabelField("Join Groups",LabelField.FOCUSABLE ){
protected boolean navigationClick(int status, int time){
Dialog.alert("Surveys Clicked!");
return true;
}
};
I want a tab bar in my application.I tried the sample code for it in blackberry but I want it at the bottom of the screen.I tried this code but it gives me uncaught runtime exception.Why this so? Whats the problem in this code?
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.image.*;
import net.rim.device.api.ui.toolbar.*;
import net.rim.device.api.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.command.*;
public class ToolbarDemo extends UiApplication
{
public static void main(String[] args)
{
ToolbarDemo theApp = new ToolbarDemo();
theApp.enterEventDispatcher();
}
public ToolbarDemo()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new ToolbarDemoScreen());
}
private final static class ToolbarDemoScreen extends MainScreen
{
public ToolbarDemoScreen()
{
if (ToolbarManager.isToolbarSupported())
{
setTitle("Toolbar Demo");
ToolbarManager manager = new ToolbarManager();
setToolbar(manager);
try
{
Bitmap myBitmap = Bitmap.getBitmapResource("myImg.jpg");
Image myImage = ImageFactory.createImage(myBitmap);
/*
* To create more buttons, Repeat the following lines
* up until manager.add()
*/
ToolbarButtonField button1 = new ToolbarButtonField(myImage, new StringProvider("butn1"));
button1.setCommandContext(new Object()
{
public String toString()
{
return "Button1";
}
});
button1.setCommand(new Command(new CommandHandler()
{
public void execute(ReadOnlyCommandMetadata metadata, Object context)
{
Dialog.alert("Executing command for " + context.toString());
}
}));
manager.add(new ToolbarSpacer(0));
manager.add(button1);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
else
{
Dialog.alert("The Toolbar is not supported on this device.");
}
}
}
}
If you are getting the Exception, Uncaught Exception: pushModalScreen called by a non-event thread then you can try following code snippet for displaying an alert.
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("The Toolbar is not supported on this device.");
}
});
And please check this question, “pushModalScreen called by a non-event thread” thrown on event thread.
Try this code
EncodedImage e1 = EncodedImage.getEncodedImageResource("home.png");
EncodedImage e2 = EncodedImage.getEncodedImageResource("map.png");
EncodedImage e3 = EncodedImage.getEncodedImageResource("members.png");
EncodedImage e4 = EncodedImage.getEncodedImageResource("message.png");
EncodedImage e5 = EncodedImage.getEncodedImageResource("settings.png");
EncodedImage e6 = EncodedImage.getEncodedImageResource("logout.png");
HorizontalFieldManager buttonPanel = new HorizontalFieldManager(Field.FIELD_TOP | Field.USE_ALL_WIDTH);
VerticalFieldManager vfm=new VerticalFieldManager();
vfm.add(new LabelField("Map"));
vfm.add(new BitmapField(e2.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("MAP");
return true;
}
});
buttonPanel.add(vfm);
buttonPanel.add(new LabelField(" "));
VerticalFieldManager vfm1=new VerticalFieldManager();
vfm1.add(new LabelField("Members"));
vfm1.add(new BitmapField(e3.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Members");
return true;
}
});
buttonPanel.add(vfm1);
VerticalFieldManager vfm2=new VerticalFieldManager();
vfm2.add(new LabelField("Message"));
vfm2.add(new BitmapField(e4.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Message");
return true;
}
});
buttonPanel.add(vfm2);
VerticalFieldManager vfm3=new VerticalFieldManager();
vfm3.add(new LabelField("Settings"));
vfm3.add(new BitmapField(e5.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Settings");
return true;
}
});
buttonPanel.add(vfm3);
VerticalFieldManager vfm4=new VerticalFieldManager();
vfm4.add(new LabelField("Logout"));
vfm4.add(new BitmapField(e6.getBitmap(),FOCUSABLE){
protected boolean navigationClick(int status, int time){
Dialog.alert("Logout");
return true;
}
});
buttonPanel.add(vfm4);
setStatus(buttonPanel);
I want to set a text in a specific label on focus of an BitmapField, and reset the text on unfocus. I am using the following code:
final BitmapField tab1 = new BitmapField(Bitmap.getBitmapResource("img/icon1.png"), FIELD_BOTTOM | BitmapField.FOCUSABLE) {
protected void drawFocus(Graphics graphics, boolean on) {
// the simplies way to draw a rectangle and this will be the
// focus
}
protected boolean navigationClick(int status, int time) {
// write here your code what you want to run the user clicks to
// the bitmap
// try something like this
Dialog.alert("Code for tab1");
return true;
}
public void setFocus(){
super.setFocus();
selectedLabel.setText("tab1");
}
public void onUnfocus(){
super.onUnfocus();
selectedLabel.setText("");
}
};
But focus is changing properly, but label is not setting at all. Where is the problem in my code?
override onFocus(int direction) instead of setFocus()
protected void onFocus(int direction) {
super.onFocus(direction);
selectedLabel.setText("tab1");
}
protected void onUnfocus() {
super.onUnfocus();
selectedLabel.setText("");
}
Use onfocus() & onUnfocus() method and replace your LabelField in both method with Invalidate() option .
I want to display an image at the bottom of the screen and make it clickable ,i have created a custom bitmap field ImageButtonField and trying to use it ,but i am getting ImageButtonField cannot be resolved.
public class ImageButtonField extends BitmapField
{
public ImageButtonField(Bitmap image) {
super(image);
}
public ImageButtonField(Bitmap image,Field location) {
//super(image,location);
}
public boolean isFocusable() {
return true;
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean trackwheelClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean keyChar(char character, int status, int time) {
if(Characters.ENTER == character || Characters.SPACE == character) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}
public NativeScreen() {
super();
LabelField title = new LabelField("Calendar DatePicker",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
hrzManager = new HorizontalFieldManager() {
protected void paintBackground(Graphics graphics) {
graphics.setBackgroundColor(0x0007F5ED);
graphics.clear();
super.paint(graphics);
}
};
hrzManager.add(title);
this.add(hrzManager);
//The background image.
backgroundBitmap = Bitmap.getBitmapResource("cryptodemo_jde.png");
// MainScreen mainScreen = new MainScreen(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_HORIZONTAL_SCROLL);
VerticalFieldManager verticalFieldManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL |
Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH ) ;
BasicEditField bef = new BasicEditField("To: ","",50,BasicEditField.FILTER_EMAIL);
//The LabelField will show up through the transparent image.
LabelField labelField = new LabelField("This is a label");
HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT);
//A bitmap field with a transparent image.
//The background image will show up through the transparent BitMapField image.
ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField);
BitmapField bitmapField1 = new BitmapField(Bitmap.getBitmapResource("attachmentdemo_jde.png"), Field.FIELD_BOTTOM);
horizontalFieldManager.add(bitmapField1);
//Add the fields to the manager.
// verticalFieldManager.add(bef);
// verticalFieldManager.add(labelField);
verticalFieldManager.add(horizontalFieldManager);
//Add the manager to the screen.
this.add(verticalFieldManager);
There's no constructor in your class that lets you do this:
ImageButtonField ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM);
The constructor that you're trying to use requires a Bitmap instance and a long primitive (for Field.FIELD_BOTTOM). You should add a constructor with the following signature for your code to work:
public ImageButtonField (Bitmap bitmap, long style){
super(bitmap, style);
}
I'm making an application in which there are few tabs on each tab click a url is called and an online xml is parsed. The data from this xml is displayed. The problem is that when the data is dispalyed the tabs disappear and only appear when i press the back button of the simulator. Whereas the data should appear below the tabs.
Please help
My UI
public class TabControl extends UiApplication {
public TabControl() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
public static void main(String[] args) {
TabControl app = new TabControl();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen implements FocusChangeListener {
private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");
private LabelField tab1;
private LabelField tab2;
private LabelField tab3;
private VerticalFieldManager tabArea;
private VerticalFieldManager tab1Manager;
private VerticalFieldManager tab2Manager;
private VerticalFieldManager tab3Manager;
public TabControlScreen() {
LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
this.setTitle(appTitle);
HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {
// 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, 700, 100, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab1();
return true;
}
};
LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab2();
return true;
}
};
LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
tabArea = displayTab3();
return true;
}
};
tab1.setFocusListener(this);
tab2.setFocusListener(this);
tab3.setFocusListener(this);
hManager.add(tab1);
hManager.add(separator);
hManager.add(tab2);
hManager.add(separator1);
hManager.add(tab3);
add(hManager);
add(new SeparatorField());
tab1Manager = new VerticalFieldManager();
tab2Manager = new VerticalFieldManager();
tab3Manager = new VerticalFieldManager();
tabArea = displayTab1();
add(tabArea);
}
public void focusChanged(Field field, int eventType) {
if (tabArea != null) {
if (eventType == FOCUS_GAINED) {
if (field == tab1) {
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
} else if (field == tab2) {
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
} else if (field == tab3) {
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
}
}
}
}
public VerticalFieldManager displayTab1() {
UiApplication.getUiApplication().pushScreen(new News());
return tab1Manager;
}
public VerticalFieldManager displayTab2() {
UiApplication.getUiApplication().pushScreen(new Power());
return tab2Manager;
}
public VerticalFieldManager displayTab3() {
UiApplication.getUiApplication().pushScreen(new Energy());
return tab3Manager;
}
}
}
My News Main Screen
public class News extends MainScreen {
public News() {
String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";
String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
for (int i = 0; i < urlData.length; i++) {
final String title = urlData[0][i];
final String id = urlData[1][i];
//add(new LinkLabel(title, i));
add(new RichTextField(title){
protected boolean navigationClick(int status,int time){
String cId = id;
String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
for(int j=0;j<bodyData.length;j++){
String body = bodyData[0][j];
add(new RichTextField(body));
}
return true;
}
});
add(new SeparatorField());
}
}
}
Now i want to open this news screen below the tabs
Please help
For your TabControl Class
public class TabControl extends UiApplication {
public TabControl() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
public static void main(String[] args) {
TabControl app = new TabControl();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen {
private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");
private LabelField tab1;
private LabelField tab2;
private LabelField tab3;
private VerticalFieldManager tabArea;
public TabControlScreen() {
LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
this.setTitle(appTitle);
HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {
// 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, 700, 100, backgroundBitmap, 0, 0);
super.paint(graphics);
}
};
tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
return true;
}
};
LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
return true;
}
};
LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
protected boolean navigationClick(int status,int time){
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
return true;
}
};
hManager.add(tab1);
hManager.add(separator);
hManager.add(tab2);
hManager.add(separator1);
hManager.add(tab3);
add(hManager);
add(new SeparatorField());
// USELESS CODE HAS BEEN REMOVED
tabArea = displayTab1();
add(tabArea);
}
public VerticalFieldManager displayTab1() {
return new News(); // RETURN THE MANAGER DIRECTLY
}
public VerticalFieldManager displayTab2() {
return new Power(); // RETURN THE MANAGER DIRECTLY
}
public VerticalFieldManager displayTab3() {
return new Energy(); // RETURN THE MANAGER DIRECTLY
}
}
}
For your News class
public class News extends VerticalFieldManager { // CHANGING THE EXTENSION SUPER CLASS
public News() {
super(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR);
String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";
String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
for (int i = 0; i < urlData.length; i++) {
final String title = urlData[0][i];
final String id = urlData[1][i];
//add(new LinkLabel(title, i));
add(new RichTextField(title){
protected boolean navigationClick(int status,int time){
String cId = id;
String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
for(int j=0;j<bodyData.length;j++){
String body = bodyData[0][j];
add(new RichTextField(body));
}
return true;
}
});
add(new SeparatorField());
}
}
}
Yes, create a seprate mainscreen or screen objects and from your parent screen you can execute the below code to open new screen using the below code:
UIApplication.getUiApplication().pushScreen(your custom screen object);
Thanks
You don't need to create 2 mainscreens in the scenario which you described.
Just create a VerticalFieldManager, add it to the mainscreen, then add content to it.
Here's a sample of code that can help you, apply it in your mainscreen constructor.
VerticalFieldManager VFM_Content = new VerticalFieldManager();
add(VFM_Content);
VFM_Content.add(/*put content here embedded in any field type you prefer*/);