Blackberry 4.5 - 如何单击 .jpg 图像?

发布于 2024-08-18 23:42:28 字数 750 浏览 4 评论 0原文

我正在 BitmapField & 中显示 .jpg 图像将其添加到 VerticalFieldManager 中。它正在显示,但我无法单击它。

我正在这样做......

Bitmap bitmap = Bitmap.getBitmapResource("image.jpg");

BitmapField bitmapField = new BitmapField(bitmap , BitmapField.FOCUSABLE)        
    {
        protected boolean navigationClick(int status, int time )
        {
            //handle click event                
            return true;
        }
    };
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(bitmapField);
add(vfm_stamp);

但是如果我像这样拍摄 .png 图像,

Bitmap bitmap = Bitmap.getBitmapResource("image.png");

那么它是可点击的。为什么会这样呢?

Blackberry 4.5 支持.jpg 图像格式。它显示 .jpg 图像,那么为什么它不可点击?我想让它可点击。

怎么办呢?

I m displaying a .jpg image in a BitmapField & adding it in a VerticalFieldManager. It is getting displayed but I cannot click on it.

I m doing it like..

Bitmap bitmap = Bitmap.getBitmapResource("image.jpg");

BitmapField bitmapField = new BitmapField(bitmap , BitmapField.FOCUSABLE)        
    {
        protected boolean navigationClick(int status, int time )
        {
            //handle click event                
            return true;
        }
    };
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(bitmapField);
add(vfm_stamp);

But if I take a .png image like

Bitmap bitmap = Bitmap.getBitmapResource("image.png");

then it is clickable. Why so?

Blackberry 4.5 supports .jpg image format. It displays a .jpg image then why its not clickable ? I want to make it clickable.

How to do it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我是有多爱你 2024-08-25 23:42:28

您可以重写方法 onFocus() 并在选择时更改其行为。

您还可以创建一个扩展 net.rim.device.api.ui.Field 的 BitmapButton

您将需要为您的 bitmapField 设置 setChangeListener()

You could override the method onFocus() and change it's behavior while selected.

You could also create a BitmapButton that extends net.rim.device.api.ui.Field

You will need to setChangeListener() for your bitmapField

暖心男生 2024-08-25 23:42:28

您可以扩展 ButtonField

package org.ci.blackberry.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;

public class BitmapButtonField45 extends ButtonField {
        private static final int STATE_NORMAL = 0;
        private static final int STATE_FOCUS = 1;
        private static final int STATE_ACTIVE = 2;
        Bitmap mNormal;
        Bitmap mFocused;
        Bitmap mActive;

        int mWidth;
        int mHeight;
        private int mState = STATE_NORMAL;

        public BitmapButtonField45(Bitmap normal, Bitmap focused, 
                Bitmap active) {
                super(CONSUME_CLICK);
                mNormal = normal;
                mFocused = focused;
                mActive = active;
                mWidth = mNormal.getWidth();
                mHeight = mNormal.getHeight();
        }
        public BitmapButtonField45(Bitmap normal, Bitmap focused) {
                this(normal, focused, focused);
        }
        protected void paint(Graphics graphics) {
                Bitmap bitmap = null;
                switch (getState()) {
                case STATE_NORMAL:
                        bitmap = mNormal;
                        break;
                case STATE_FOCUS:
                        bitmap = mFocused;
                        break;
                case STATE_ACTIVE:
                        bitmap = mActive;
                        break;
                default:
                        bitmap = mNormal;
                }
                graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
                                bitmap, 0, 0);
        }

        public int getState() {
                return mState;
        }

        protected void applyTheme()
        {}
        protected void onFocus(int direction) {
                mState = STATE_FOCUS;
                super.onFocus(direction);
        }

        protected void onUnfocus() {
                mState = STATE_NORMAL;
                super.onUnfocus();
        }

        protected boolean navigationClick(int status, int time) {
                mState = STATE_ACTIVE;
                return super.navigationClick(status, time);
        }

        protected boolean navigationUnclick(int status, int time) {
                mState = STATE_NORMAL;
                return super.navigationUnclick(status, time);
        }

        public int getPreferredWidth() {
                return mWidth;
        }

        public int getPreferredHeight() {
                return mHeight;
        }

        protected void layout(int width, int height) {
                setExtent(getPreferredWidth(), getPreferredHeight());
        }
}

使用示例:PuzzleApp.java

You can extand ButtonField:

package org.ci.blackberry.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;

public class BitmapButtonField45 extends ButtonField {
        private static final int STATE_NORMAL = 0;
        private static final int STATE_FOCUS = 1;
        private static final int STATE_ACTIVE = 2;
        Bitmap mNormal;
        Bitmap mFocused;
        Bitmap mActive;

        int mWidth;
        int mHeight;
        private int mState = STATE_NORMAL;

        public BitmapButtonField45(Bitmap normal, Bitmap focused, 
                Bitmap active) {
                super(CONSUME_CLICK);
                mNormal = normal;
                mFocused = focused;
                mActive = active;
                mWidth = mNormal.getWidth();
                mHeight = mNormal.getHeight();
        }
        public BitmapButtonField45(Bitmap normal, Bitmap focused) {
                this(normal, focused, focused);
        }
        protected void paint(Graphics graphics) {
                Bitmap bitmap = null;
                switch (getState()) {
                case STATE_NORMAL:
                        bitmap = mNormal;
                        break;
                case STATE_FOCUS:
                        bitmap = mFocused;
                        break;
                case STATE_ACTIVE:
                        bitmap = mActive;
                        break;
                default:
                        bitmap = mNormal;
                }
                graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
                                bitmap, 0, 0);
        }

        public int getState() {
                return mState;
        }

        protected void applyTheme()
        {}
        protected void onFocus(int direction) {
                mState = STATE_FOCUS;
                super.onFocus(direction);
        }

        protected void onUnfocus() {
                mState = STATE_NORMAL;
                super.onUnfocus();
        }

        protected boolean navigationClick(int status, int time) {
                mState = STATE_ACTIVE;
                return super.navigationClick(status, time);
        }

        protected boolean navigationUnclick(int status, int time) {
                mState = STATE_NORMAL;
                return super.navigationUnclick(status, time);
        }

        public int getPreferredWidth() {
                return mWidth;
        }

        public int getPreferredHeight() {
                return mHeight;
        }

        protected void layout(int width, int height) {
                setExtent(getPreferredWidth(), getPreferredHeight());
        }
}

Examples of use: PuzzleApp.java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文