如何在字段类中添加位图字段或单击监听器?

时间:2012-06-18 07:27:47

标签: blackberry field bitmapfield

我的Custom_Field课就是这样:

public class Custom_BottomField extends Field {

private Bitmap _backgroundBitmap = Bitmap
        .getBitmapResource("footer_bar.png");

private Bitmap finance = Bitmap.getBitmapResource("icon_economy.png"),
        special = Bitmap.getBitmapResource("icon_title.png"),
        forum = Bitmap.getBitmapResource("icon_forum.png"),
        discussion = Bitmap.getBitmapResource("icon_discussion.png"),
        other = Bitmap.getBitmapResource("icon_other.png");

private BitmapField financebtn, specialbtn, forumbtn, discussionbtn,
        otherbtn;

Custom_BottomField() {
    Background background = BackgroundFactory
            .createBitmapBackground(_backgroundBitmap);
    setBackground(background);
}

protected void layout(int width, int height) {
    width = Math.min(width, getPreferredWidth());
    height = Math.min(height, getPreferredHeight());
    setExtent(width, height);
}

public int getPreferredHeight() {
    return 70;
}

public int getPreferredWidth() {
    return Display.getWidth();
}

protected void paint(Graphics graphics) {
    int rectHeight = getPreferredHeight();
    int rectWidth = getPreferredWidth();
    graphics.drawRect(0, 0, rectWidth, rectHeight);
    graphics.drawBitmap(getGap(), 5, finance.getWidth(),
            finance.getHeight(), finance, 0, 0);
    graphics.drawBitmap(rectWidth / 5 + getGap(), 5, special.getWidth(),
            special.getHeight(), special, 0, 0);
    graphics.drawBitmap(rectWidth * 2 / 5 + getGap(), 5, forum.getWidth(),
            forum.getHeight(), forum, 0, 0);
    graphics.drawBitmap(rectWidth * 3 / 5 + getGap(), 5,
            discussion.getWidth(), discussion.getHeight(), discussion, 0, 0);
    graphics.drawBitmap(rectWidth * 4 / 5 + getGap(), 5, other.getWidth(),
            other.getHeight(), other, 0, 0);
}

private int getGap() {
    return ((getPreferredWidth() / 5) - finance.getWidth()) / 2;
}

private void Button() {
    financebtn = new BitmapField(finance, BitmapField.FOCUSABLE) {
        protected boolean navigationClick(int status, int time) {
            MyApp.getUiApplication().pushScreen(new Main_ParticulatCategoryAllNews());
            return true;
        }
    };
}
}

以上课程在this图片

中突出显示

我无法在Field课程中添加BitmapField,因为我想点击按钮转到Main_ParticulatCategoryAllNews课程。

1 个答案:

答案 0 :(得分:0)

通过扩展HorizontalFieldManager并使用add()

解决