如何添加另一行位图图像

时间:2009-11-04 07:53:45

标签: blackberry

class Scr extends MainScreen {

    public Scr() {

        TableLayoutManager outerTable = new TableLayoutManager(new int[]
                                                                      {
                             TableLayoutManager.USE_PREFERRED_SIZE,
                             TableLayoutManager.SPLIT_REMAINING_WIDTH
                            },0);
        TableLayoutManager innerTable = new TableLayoutManager(new int[]
                                                                       {
                                                                       TableLayoutManager. USE_PREFERRED_SIZE,
                                                                       TableLayoutManager.USE_PREFERRED_SIZE

                                                                       }, Manager.USE_ALL_WIDTH);

        innerTable.add(new LabelField("titleField"));
        innerTable.add(new LabelField("title"));
        innerTable.add(new LabelField("descriptionfield"));
        innerTable.add(new LabelField("description"));
        innerTable.add(new LabelField("rating field"));
        innerTable.add(new LabelField("***"));
        outerTable.add(new BitmapField(Bitmap.getBitmapResource("mac.png"),Field.FOCUSABLE));
        outerTable.add(innerTable);
        add(outerTable);

        outerTable.add(new BitmapField(Bitmap.getBitmapResource("fire.png"),Field.FOCUSABLE));
        outerTable.add(innerTable);
        add(outerTable);

    }

当我将另一个Bitmap和innerTable添加到outerTable,并将outerTable添加到屏幕时。应用程序提供运行时jvm错误104 “当一个经理人已经成为父母时,他就加入了这个领域。”

当我向outerTable添加另一个innerTable时出现问题。不是在我将Bitmap添加到outerTable时。

1 个答案:

答案 0 :(得分:2)

innerTable已添加到outerTable,您无法再次添加。这是因为控件的一个实例定义了一个成员,它告诉控件及其显示方式,如父和大小。那些成员显然不能拥有多种价值观。所以你必须创建另一个控件,它复制第一个控件,以便它可以拥有自己的父控件和大小。

在这里,您必须创建TableLayoutManager的另一个实例(可能将其命名为innerTable2)并将其添加到outerTable。此外,outerTable被添加2次,这将触发相同的错误,您必须创建另一个outerTable的实例。

你应该写:(请注意,有更好的方法可以做到......)

public Scr() {
    TableLayoutManager outerTable = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.SPLIT_REMAINING_WIDTH
                        },0);
    TableLayoutManager outerTable2 = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.SPLIT_REMAINING_WIDTH
                        },0);
    TableLayoutManager innerTable = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.USE_PREFERRED_SIZE
                        },Manager.USE_ALL_WIDTH);
    TableLayoutManager innerTable2 = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.USE_PREFERRED_SIZE
                        },Manager.USE_ALL_WIDTH);

    innerTable.add(new LabelField("titleField"));
    innerTable.add(new LabelField("title"));
    innerTable.add(new LabelField("descriptionfield"));
    innerTable.add(new LabelField("description"));
    innerTable.add(new LabelField("rating field"));
    innerTable.add(new LabelField("***"));
    outerTable.add(new BitmapField(Bitmap.getBitmapResource("mac.png"),Field.FOCUSABLE));
    outerTable.add(innerTable);
    add(outerTable);

    innerTable2.add(new LabelField("titleField"));
    innerTable2.add(new LabelField("title"));
    innerTable2.add(new LabelField("descriptionfield"));
    innerTable2.add(new LabelField("description"));
    innerTable2.add(new LabelField("rating field"));
    innerTable2.add(new LabelField("***"));
    outerTable2.add(new BitmapField(Bitmap.getBitmapResource("fire.png"),Field.FOCUSABLE));
    outerTable2.add(innerTable2);
    add(outerTable2);
}

请注意,这里有很多重复的代码。您可以将innerTable创建因素分解为一个创建TableLayoutManager的函数,添加所有必需的标签并返回新配置的TableLayoutManager。

相关问题