简体   繁体   中英

Drawing Border in BlackBerry ListField

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 this, 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!

没有所有代码很难说清楚,但是drawText调用使用y值,而其他调用则不使用y值,因此可以解释为什么它们都在同一位置绘制。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM