【问题标题】:BitmapField click does not work on Blackberry applicationBitmapField 单击不适用于黑莓应用程序
【发布时间】:2011-06-06 22:52:50
【问题描述】:

如果我单击要推送另一个屏幕的位图字段,我水平排列了 7 个 bimapfield 这是我的代码,但我没有得到另一个屏幕,谁能帮我看看这段代码有什么问题

BitmapField bitmap1 = new BitmapField(
    Bitmap.getBitmapResource("profile_n.png"),FOCUSABLE | DrawStyle.HCENTER)
{
    protected void onFocus(int direction)
    {
        rollno=1;
        this.getScreen().invalidate();
    }
    protected void onUnfocus()
    {

    }   
    protected boolean navigationClick(int status, int time){
           UiApplication.getUiApplication().popScreen(getScreen());
            UiApplication.getUiApplication().pushScreen(new AccMainScreen());
        return true;
    }
};

【问题讨论】:

    标签: blackberry java-me


    【解决方案1】:

    您可以使用自定义字段来保存图像并像按钮一样使用而不是位图字段。 这是我建议的代码:

    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Graphics;
    public class CustomButton extends Field{
    
        protected Bitmap icon;
        protected int fieldWidth;
        protected int fieldHeight;
    
        public CustomButton (String iconSource,long style) {
            super(style);
            icon = Bitmap.getBitmapResource(iconSource);
            fieldHeight = icon.getHeight();
            fieldWidth = icon.getWidth();
        }
    
        public int getPreferredWidth() {
            return fieldWidth;
        }
    
        public int getPreferredHeight() {
            return fieldHeight;
        }
        protected void layout(int arg0, int arg1) {
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
        protected void drawFocus(Graphics graphics, boolean on){ }
    
        protected void paint(Graphics graphics) {
            graphics.fillRect(0, 0, fieldWidth, fieldHeight);
            graphics.drawBitmap(0,0, fieldWidth, fieldHeight, icon, 0, 0);
        }
        protected boolean navigationClick(int status, int time) {
            fieldChangeNotify(0);
            return true;
        }
    }
    

    您可以像使用默认按钮一样使用此按钮,并使用 setChangeListener 函数更改它的侦听器。

    CustomButton aButton = new CustomButton ("graphics/someIcon.png");
    aButton.setChangeListener(new FieldChangeListener() {
        public void fieldChanged(Field field, int context) {
            UiApplication.getUiApplication().popScreen(getScreen());
            UiApplication.getUiApplication().pushScreen(new AccMainScreen());   
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多