问题
I searched how to set header and footer in BlackBerry and I found the functions setTitle()
and setStatus()
.
My problem is I have created a class that extends VerticalFieldManager
. In VerticalFieldManager
, it is not showing me setStatus
function as this is function of MainScreen
class.
回答1:
You're right. A VerticalFieldManager
does not allow you to setStatus()
directly.
It's important to understand the relationship between the classes in the BlackBerry UI framework.
First of all, there are Screen
classes. Normally, a Screen
will take up the entire device screen. You can have many different Screen
classes in your app. Maybe one Screen
for a splash image, one screen for a map view, one screen for settings, etc.
Inside your screens, you will often have Manager
classes. A VerticalFieldManager
is a kind of Manager
that arranges its contents top-to-bottom, in the order that you add them. A Manager
holds a group of related objects, but it does not have to span the full screen height, or width.
Inside your managers, you will usually have multiple Field
objects. A Field
is the individual item in the heirarchy. ButtonField
, EditField
, or BrowserField
are all kinds of fields. They will usually be added to managers (containers). Those managers will then usually be added to screens.
So, in your case, I think what you should have is a screen class. In that screen class, you will set the header and footer by calling setTitle()
and setStatus()
. The content between the header and footer will all be contained in a VerticalFieldManager
that you add to the screen. Something like this:
public class MyScreen extends MainScreen {
public MyScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
// set a header for this screen
setTitle("My Header / Title");
// screen contents go in the vertical field manager
// NOTE: you can replace VerticalFieldManager with your own class
// that extends Manager, or VerticalFieldManager, if you like
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(new LabelField("One"));
vfm.add(new ButtonField("Two", ButtonField.CONSUME_CLICK));
vfm.add(new CheckboxField("Three", true));
add(vfm);
// use a bitmap as a footer
Bitmap footer = Bitmap.getBitmapResource("footer.png");
setStatus(new BitmapField(footer));
}
}
来源:https://stackoverflow.com/questions/15127766/set-header-and-footer-in-blackberry-in-verticalfieldmanager