使用自定义位图字段时出现问题

时间:2012-03-18 16:07:43

标签: blackberry

我想在屏幕底部显示一个图像并使其可点击,我创建了一个自定义位图字段ImageButtonField并尝试使用它,但我得到的ImageButtonField无法解析。

public class ImageButtonField extends BitmapField
{
    public ImageButtonField(Bitmap image) {
        super(image);
    }

    public ImageButtonField(Bitmap image,Field location) {
        //super(image,location);
    }
    public boolean isFocusable() {
        return true;
    }

    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean trackwheelClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean keyChar(char character, int status, int time) {
        if(Characters.ENTER == character || Characters.SPACE == character) {
            fieldChangeNotify(0);
            return true;
        }
        return super.keyChar(character, status, time);
    }
}


  public NativeScreen() {


           super();
               LabelField title = new LabelField("Calendar DatePicker",
                               LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);

              hrzManager = new HorizontalFieldManager() {
                    protected void paintBackground(Graphics graphics) {
                            graphics.setBackgroundColor(0x0007F5ED);
                               graphics.clear();
                              super.paint(graphics);
                 }
              };
             hrzManager.add(title);   
             this.add(hrzManager);
               //The background image.
    backgroundBitmap = Bitmap.getBitmapResource("cryptodemo_jde.png");

   // MainScreen mainScreen = new MainScreen(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_HORIZONTAL_SCROLL);

    VerticalFieldManager verticalFieldManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL | 
        Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH ) ;

    BasicEditField bef = new BasicEditField("To: ","",50,BasicEditField.FILTER_EMAIL);

    //The LabelField will show up through the transparent image.
    LabelField labelField = new LabelField("This is a label");

    HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.USE_ALL_HEIGHT);
    //A bitmap field with a transparent image.
    //The background image will show up through the transparent BitMapField image.
    ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"),  Field.FIELD_BOTTOM);
        horizontalFieldManager.add(bitmapField);
    BitmapField bitmapField1 = new BitmapField(Bitmap.getBitmapResource("attachmentdemo_jde.png"), Field.FIELD_BOTTOM);
    horizontalFieldManager.add(bitmapField1);

    //Add the fields to the manager.
   // verticalFieldManager.add(bef);
   // verticalFieldManager.add(labelField);
    verticalFieldManager.add(horizontalFieldManager);

    //Add the manager to the screen.
    this.add(verticalFieldManager);

1 个答案:

答案 0 :(得分:1)

你班上没有可以让你这样做的构造函数:

ImageButtonField ImageButtonField bitmapField = new ImageButtonField(Bitmap.getBitmapResource("pimdemo_jde.png"), Field.FIELD_BOTTOM);

您尝试使用的构造函数需要一个Bitmap实例和一个 long primitive (对于Field.FIELD_BOTTOM)。您应该添加一个带有以下签名的构造函数,以使代码起作用:

public ImageButtonField (Bitmap bitmap, long style){
    super(bitmap, style);
}