我一直在努力在 Blackberry 上动态创建多个 VerticalFieldManager。每个 subManager 都会向用户显示不同的数据。并且每个 subManager 在屏幕上会有不同的位置。所以我创建了一个具有“mainManager”的类和另一个创建“submanagers”的类,然后我调用mainManager.add(new TheClassExtendingVerticalFieldManager);
将 subManagers 添加到 mainManager。问题是我只得到一个 subManager 而不是三个。我正在使用填充来分隔经理。这是我使用的代码。请指导我正确的方向,将不胜感激。
创建子管理器的类
public class ProgramListView extends VerticalFieldManager{
private VerticalFieldManager subManager;
private int _height;
public ProgramListView(int height){
this._height = height;
// subManager = new VerticalFieldManager(
// Manager.NO_HORIZONTAL_SCROLL | Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR |
// Manager.NO_HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH)
//
// {
//
//
// };
}
public int get_height() {
return _height;
}
public void set_height(int _height) {
this._height = _height;
}
public void setCoordinates(int x, int y){
setPosition(100,140);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth();
int displayHeight = maxHeight;
this.setPosition(300, 300);
super.sublayout( 40, 40);
setPadding(this.get_height(), 0, 0, 0);
setExtent(displayWidth, this.get_height());
}
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.BLUE);//blue
graphics.clear();
super.paint(graphics);
}
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
}
mainManager 类
public class ProgramLayout extends MainScreen {
private HorizontalFieldManager mainManager;
private int deviceWidth = Display.getWidth();
private int deviceHeight = Display.getHeight();
private Vector subManagers;
private int theheight;
public ProgramLayout(){
setToolbar();
subManagers = new Vector();
theheight = 100;
mainManager = new HorizontalFieldManager(Manager.VERTICAL_SCROLL | Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = deviceWidth;
int displayHeight = deviceHeight;
super.sublayout( displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
};
for (int i = 0; i < 3; i++) {
theheight = theheight+100;
subManagers.addElement(new ProgramListView(theheight));
}
for (int i = 0; i < subManagers.size(); i++) {
mainManager.add((VerticalFieldManager)subManagers.elementAt(i));
}
this.add(mainManager);
}
提前致谢