开发者

Drawing Border in BlackBerry ListField

开发者 https://www.devze.com 2023-02-07 13:45 出处:网络
I have implemented a ListField for my BlackBerry application with a custom ListFieldCallback. It is working well, with the exception of two problems:

I have implemented a ListField for my BlackBerry application with a custom ListFieldCallback. It is working well, with the exception of two problems:

First, my specified bitmap is only drawing in the first row. It is not drawing in any other row following (the text draws fine, however).

Second, I want to draw a blue border around the currently selected ListField element. To do 开发者_如何学JAVAthis, I have overridden the drawFocus() of the ListField to contain nothing and I have also set the ListField to invalidate() on the navigationMovement() method. The border is being drawn on the first row, but not any others. Can anyone figure out why? Here is my relevant code:

The ListField instantiation:

ListField lf = new ListField() {
            protected void drawFocus(Graphics graphics, boolean on) {
            }

            protected boolean navigationMovement(int dx, int dy,
                    int status, int time) {
                this.invalidate(this.getSelectedIndex());
                return super.navigationMovement(dx, dy, status, time);
            }
            protected boolean navigationClick(int status, int time) {
                return true;
            }
        };

        lf.setEmptyString("No items.", DrawStyle.HCENTER);
        _callback = new ListCallback(vector, Bitmap
                .getBitmapResource("image.png"));
        lf.setCallback(_callback);
        add(lf);

        lf.setSize(vector.size());

The custom ListField Callback:

if (index == list.getSelectedIndex()) {
        g.setColor(0x4096cc);
        g.drawBitmap(5, (bitmapHeight - fontHeight) * 2,
                _bitmap.getWidth(), _bitmap.getHeight(), _bitmap, 0, 0);
        g.drawText(text, _bitmap.getWidth() + 15,
                y, 0, w);
         g.drawRect(0, 0, list.getWidth(), list.getRowHeight());
    } else {
        g.setColor(0x4096cc);
        g.drawBitmap(5, (bitmapHeight - fontHeight) * 2,
                _bitmap.getWidth(), _bitmap.getHeight(), _bitmap, 0, 0);
        g.drawText(text, _bitmap.getWidth() + 15,
                y, 0, w);
    }

Thanks!


Hard to tell exactly without all the code, but your drawText call uses the y value while the other calls don't, so that explains why they're all drawing at the same spot.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号