Changes

Jump to: navigation, search

Lab BlackBerry Example

2,105 bytes added, 13:53, 27 February 2011
no edit summary
''File->New->Others->BlackBerry Project''
''Note: If you really want really to learn how to build a BB app, then in the wizard choose the ''Empty Application '' option.''
The structure of BB project will be defined, but as the level on of code generation, one will get only an empty Java app, with a code similar with thisone:
<source lang="java">
package mypackage;
a. The class of that object must implement the ''FieldChangeListener'' interface.
b. The source of the event, namely the button object must add this particular listener to the collection of listeners.
------------------
Here is a generic code sample:
Here is a generic code sample:
1. Build the source object, the button:
ButtonField buttonField = new ButtonField("Test Button");
3. Add the listener object to the list of source listeners:
buttonField.setChangeListener(listener);
 
Important note: For expressiveness the steps 2 and 3 are combined to produce code like this:
 
buttonField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ButtonField buttonField = (ButtonField) field;
System.out.println("Button pressed: " + buttonField.getLabel());
}
});
 
 
 
-----------------
Here is the code you must write to add the button ''_buttonGoBack'' to the second screen
add(_buttonGoBack);
</source>
 
If you want to add some specific color to the second screen you may use ''net.rim.device.api.ui.container.VerticalFieldManager''. The vertical field manager lays out fields top to bottom in a single column. One can use the manager object to set the background of an element.
 
Let us suppose that you want the second screen to have the coral color. Therefore, you should use the code like this one:
 
VerticalFieldManager manager = (VerticalFieldManager) getMainManager();
manager.setBackground(BackgroundFactory.createSolidBackground(Color.CORAL));
 
Eventually, your second screen class called ''NextScreen'' could be implemented with the code like this one:
 
<source lang="java">
package mypackage;
 
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.decor.BackgroundFactory;
 
class NextScreen extends MainScreen {
 
public NextScreen() {
 
setTitle(new LabelField("Second Screen !", LabelField.USE_ALL_WIDTH));
VerticalFieldManager manager = (VerticalFieldManager) getMainManager();
manager.setBackground(BackgroundFactory.createSolidBackground(Color.CORAL));
 
add(new RichTextField("Here is the second activity", Field.NON_FOCUSABLE));
 
ButtonField _buttonGoBack = new ButtonField("Go Back",
ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
 
_buttonGoBack.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().popScreen();
}
});
add(_buttonGoBack);
}
}
</source>
-------
 
In Eclipse, the Project structure should look similar to:
[[File:BBLab-Project.png]]

Navigation menu