Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何动态创建多个VerticalFieldManager_Java_Blackberry_Blackberry Jde - Fatal编程技术网

Java 如何动态创建多个VerticalFieldManager

Java 如何动态创建多个VerticalFieldManager,java,blackberry,blackberry-jde,Java,Blackberry,Blackberry Jde,我一直在努力在Blackberry上动态创建多个VerticalFieldManager。每个子管理器将向用户显示不同的数据。每个子管理器在屏幕上都有不同的位置。因此,我创建了一个类,它有一个“mainManager”,另一个类创建了“submanagers”,然后我调用mainManager.add(新的TheClassExtendingVerticalFieldManager)将子管理器添加到mainManager。问题是我只得到一个子管理器,而不是三个子管理器。我用填充来分隔经理。这是我使

我一直在努力在Blackberry上动态创建多个VerticalFieldManager。每个子管理器将向用户显示不同的数据。每个子管理器在屏幕上都有不同的位置。因此,我创建了一个类,它有一个“mainManager”,另一个类创建了“submanagers”,然后我调用
mainManager.add(新的TheClassExtendingVerticalFieldManager)
将子管理器添加到mainManager。问题是我只得到一个子管理器,而不是三个子管理器。我用填充来分隔经理。这是我使用的代码。请给我指引正确的方向,我将不胜感激

创建子管理器的类

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();
    }

} 
主管理器类

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);

    }
公共类程序布局扩展主屏幕{
私人HorizontalFieldManager mainManager;
private int deviceWidth=Display.getWidth();
private int deviceHeight=Display.getHeight();
私有向量子管理器;
私人室内高度;
公共规划布局(){
setToolbar();
子管理器=新向量();
高度=100;
mainManager=new HorizontalFieldManager(Manager.VERTICAL_SCROLL|Manager.USE_ALL_WIDTH|Manager.USE_ALL_HEIGHT)
{
受保护的空位子布局(int-maxWidth、int-maxHeight)
{
int displayWidth=设备宽度;
int displayHeight=设备高度;
超级子布局(显示宽度、显示高度);
setExtent(显示宽度、显示高度);
}
公共空间绘制(图形)
{
图形.背景色(颜色.黑色);
graphics.clear();
超级油漆(图形);
}
public int getPreferredWidth(){
//TODO自动生成的方法存根
返回Display.getWidth();
}
};
对于(int i=0;i<3;i++){
高度=高度+100;
addElement(新程序列表视图(theheight));
}
对于(int i=0;i
提前感谢

试试这个:

    for (int i = 0; i < 3; i++) {
        theheight = theheight+100;
         mainManager.add(new ProgramListView(theheight));
    }
    this.add(mainManager);
for(int i=0;i<3;i++){
高度=高度+100;
添加(新程序列表视图(高度));
}
添加(mainManager);

仅详细说明Eugen Martynov指出的内容,您的
mainManager
是一个
HorizontalFieldManager
,这意味着它将按照您添加子字段的顺序()水平地排列子字段。它会根据您调用
add()
的顺序自动为您处理布局

但是,每个子级都是
ProgramListView
的一个实例,并在中返回Display.getWidth() getPreferredWidth():

public int getPreferredWidth(){
//TODO自动生成的方法存根
返回Display.getWidth();
}
所以,第一个占据了整个屏幕的宽度,接下来的两个必须在它的右边(但是你已经占据了整个屏幕的宽度)


您是否希望这三个
ProgramListView
垂直堆叠?然后,
mainManager
应更改为
VerticalFieldManager
。使用
VerticalFieldManager
,调用
add()
对于三个不同的
程序列表视图
子字段将自动垂直排列。

可能是因为您使用的是HorizontalFieldManager,而sub-manager类被编程为占据所有屏幕宽度,只是为了详细说明Eugen指出的内容,您的
mainManager
是一个
HorizontalFieldManager
,它这意味着它将按照您添加子字段的顺序水平排列子字段。但是,每个子字段都是
ProgramListView
的一个实例,并在
getPreferredWidth()中返回
Display.getWidth()
。所以,第一个占据了整个屏幕的宽度。你想让这三个
ProgramListView
s垂直堆叠吗?那么,
mainManager
应该是一个
VerticalFieldManager
。谢谢各位。将主管理器更改为垂直就成功了。嘿@Nate如果你把你的评论作为一个实际答案,我可以回答选择它作为正确答案。感谢按要求作为答案发布的建议:)