用于触摸屏的自定义ObjectChoiceField

时间:2011-03-23 09:16:48

标签: blackberry combobox width touch field

我编写了自定义的ObjectChoiceField。 为了拉伸ComboBox屏幕的整个宽度。 课程如下:

public class ComboBox extends ObjectChoiceField {
    private final int PADDING_HEIGHT = 20;
    private final int width;
    private final int height;

    public ComboBox(Object[] choices, int width) {
        super("", choices, 0, FIELD_LEFT);
        this.width = width;
        this.height = getFont().getHeight() + PADDING_HEIGHT;
        this.setMinimalWidth(width);
    }

    public int getPreferredHeight() {
        return height;
    }

    public int getPreferredWidth() {
        return width;
    }

    protected void layout(int w, int h) {
        setExtent(width, height);
    }

    public void getFocusRect(XYRect rect) {
        rect.set(getFont().getAdvance(getLabel()), 0, width, height);
    }

}

它可以在模拟器9700上运行,但在9800上不起作用。我看到抛出下一个堆栈跟踪:

C3CD62E3320B498 time: Wed Mar 23 15:10:29 2011  severity:1 type:3 app:Java Exception data:
    IllegalArgumentException
    No detail message
    net_rim_cldc-13(4C48DD41)
     Graphics
     <private>
     0x2726
    net_rim_cldc-13(4C48DD41)
     Graphics
     tileRop
     0x1C92
    net_rim_cldc-19(4C48DD41)
     BitmapBackground
     draw
     0xC4F
    net_rim_cldc-16(4C48DD41)
     ChoiceBox
     draw
     0x42AE
    net_rim_cldc-16(4C48DD41)
     ChoiceField
     paint
     0x55B0
    net_rim_cldc-12(4C48DD41)
     Field
     paintSelf
     0x6CF5
    net_rim_cldc-13(4C48DD41)
     Manager
     paintChild
     0x7040
    net_rim_cldc-19(4C48DD41)
     VerticalFieldManager
     subpaint
     0xC6F0
    net_rim_cldc-13(4C48DD41)
     Manager
     <private>
     0x91C8
    net_rim_cldc-13(4C48DD41)
     Manager
     paint
     0x7BA3
    net_rim_cldc-12(4C48DD41)
     Field
     paintSelf
     0x6CF5
    net_rim_cldc-13(4C48DD41)
     Manager
     paintSelf
     0x7C14
    net_rim_cldc-13(4C48DD41)
     Manager
     paintChild
     0x7040
    net_rim_cldc-19(4C48DD41)
     VerticalFieldManager
     subpaint
     0xC6F0
    net_rim_cldc-13(4C48DD41)
     Manager
     <private>
     0x91C8
    net_rim_cldc-13(4C48DD41)
     Manager
     paint
     0x7BA3
    net_rim_cldc-12(4C48DD41)
     Field
     paintSelf
     0x6CF5
    net_rim_cldc-13(4C48DD41)
     Manager
     paintSelf
     0x7C14
    net_rim_cldc-13(4C48DD41)
     Manager
     paintChild
     0x7040
    net_rim_cldc-13(4C48DD41)
     Manager
     subpaint
     0x72C2
    net_rim_cldc-13(4C48DD41)
     Manager
     <private>
     0x91C8
    net_rim_cldc-13(4C48DD41)
     Manager
     paint
     0x7BA3
    net_rim_cldc-12(4C48DD41)
     Field
     paintSelf
     0x6CF5
    net_rim_cldc-13(4C48DD41)
     Manager
     paintSelf
     0x7C14
    net_rim_cldc-13(4C48DD41)
     Manager
     paintChild
     0x7040
    net_rim_cldc-13(4C48DD41)
     Manager
     subpaint
     0x72C2
    net_rim_cldc-13(4C48DD41)
     Manager
     <private>
     0x91C8
    net_rim_cldc-13(4C48DD41)
     Manager
     paint
     0x7BA3
    net_rim_cldc-12(4C48DD41)
     Field
     paintSelf
     0x6CF5
    net_rim_cldc-13(4C48DD41)
     Manager
     paintSelf
     0x7C14
    net_rim_cldc-13(4C48DD41)
     Manager
     paintChild
     0x7040
    net_rim_cldc-14(4C48DD41)
     Screen
     paint
     0x3725
    net_rim_cldc-12(4C48DD41)
     Field
     paintSelf
     0x

也许这是因为我用来构建项目bb工具... 你有想法如何解决?

2 个答案:

答案 0 :(得分:1)

您需要从布局方法调用super.layout(w,h),以便ObjectChoiceField可以正确设置其内部状态。在super.layout之后,您可以进行所需的任何调整。

答案 1 :(得分:-1)

布局导致问题。如果你删除它,它的工作原理。

也许你可以设置宽度,但我不确定身高。