如何自定义列表字段项?

发布于 2024-09-10 03:08:32 字数 1798 浏览 2 评论 0原文

我是黑莓开发的新手。我的应用程序包含五个列表项,每个列表项都有字符串。我的要求是,当选择一个单元格时,它应该放大,其他项目自动调整其中的空间。 我为列表项采用了两种类型的图像,一种用于一般视图,另一种用于在用户单击它时显示所选项目,该图像比以前的高度更高。

但问题是,当我选择一个项目时,它会放大并重叠在下一个项目上,并且不会显示完整的项目,也不会调整它们之间的空间。 谁能给我这个问题的解决方案。我正在使用以下代码片段...

_listField.setCallback(this);
    _listField.setRowHeight(45);
    _listField.setChangeListener(this);

public void drawListRow(ListField arg0, Graphicsgraphics, int index, int y, int 宽度) {

    if (listFieldIndex != index) {

        graphics.drawBitmap(0, y, listBkgrnd.getWidth(), listBkgrnd
                .getHeight(), listBkgrnd, 0, 0);

        graphics.setColor(0xAA0000);
        graphics.setFont(this.getFont().derive(Font.BOLD, 17));
        graphics.drawText(((Station) _stationList.elementAt(index))
                .getStationName(), 15, y + 15, 0,
                (listBkgrnd.getWidth() - 70));

        graphics.setColor(0x770000);
        graphics.setFont(this.getFont().derive(Font.PLAIN, 13));

        // graphics.drawText(
        // ((Station) _stationList.elementAt(index)).getCT(), 15,
        // y + 40, 0, (listBkgrnd.getWidth() - 65));

    } else {

        graphics.drawBitmap(0, y, playBkgrnd.getWidth(), playBkgrnd
                .getHeight(), playBkgrnd, 0, 0);

        graphics.setColor(0xAA0000);
        graphics.setFont(this.getFont().derive(Font.BOLD, 17));
        graphics.drawText(((Station) _stationList.elementAt(index))
                .getStationName(), 15, y + 15, 0,
                (playBkgrnd.getWidth() - 70));

        graphics.setColor(0x770000);
        graphics.setFont(this.getFont().derive(Font.PLAIN, 13));

        graphics.drawText(
                    s.getCT(), 15,
                    y + 40, 0, (playBkgrnd.getWidth() - 65));
    }
}

I am new to Blackberry development.My application contain five list items having strings each item.My requirement is when one cell is selected it should enlarge and other items adjust space automatically among them.
I took two types of images for list items one for general view and one for displaying the selected item when user clicked on it which is of more height than previous.

But the problem is when I selected one item it is enlarging and overlapped on the next item and is not displaying full item and not adjusting the space among them.
can anyone give me the solution for this. I am using the following code snippet....

_listField.setCallback(this);
    _listField.setRowHeight(45);
    _listField.setChangeListener(this);

public void drawListRow(ListField arg0, Graphics graphics, int index,
int y, int width) {

    if (listFieldIndex != index) {

        graphics.drawBitmap(0, y, listBkgrnd.getWidth(), listBkgrnd
                .getHeight(), listBkgrnd, 0, 0);

        graphics.setColor(0xAA0000);
        graphics.setFont(this.getFont().derive(Font.BOLD, 17));
        graphics.drawText(((Station) _stationList.elementAt(index))
                .getStationName(), 15, y + 15, 0,
                (listBkgrnd.getWidth() - 70));

        graphics.setColor(0x770000);
        graphics.setFont(this.getFont().derive(Font.PLAIN, 13));

        // graphics.drawText(
        // ((Station) _stationList.elementAt(index)).getCT(), 15,
        // y + 40, 0, (listBkgrnd.getWidth() - 65));

    } else {

        graphics.drawBitmap(0, y, playBkgrnd.getWidth(), playBkgrnd
                .getHeight(), playBkgrnd, 0, 0);

        graphics.setColor(0xAA0000);
        graphics.setFont(this.getFont().derive(Font.BOLD, 17));
        graphics.drawText(((Station) _stationList.elementAt(index))
                .getStationName(), 15, y + 15, 0,
                (playBkgrnd.getWidth() - 70));

        graphics.setColor(0x770000);
        graphics.setFont(this.getFont().derive(Font.PLAIN, 13));

        graphics.drawText(
                    s.getCT(), 15,
                    y + 40, 0, (playBkgrnd.getWidth() - 65));
    }
}

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

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

发布评论

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

评论(1

や三分注定 2024-09-17 03:08:32

BlackBerry 上的列表字段假定所有行的高度相同。

要获得您想要的效果,请在 VerticalFieldManager 中使用一堆可选字段,您将获得与 ListField 类似的效果。确保您的项目可聚焦,并在它们获得或失去焦点时调用 updateLayout,然后在您的 layout 方法中,根据字段是否获得焦点来设置字段的高度。类似下面的大纲:

public class CustomListFieldItem extends Field {

    public boolean isFocusable() {
        return true;
    }

    protected void onFocus(int direction) {
        super.onFocus(direction);
        updateLayout();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        updateLayout();
    }

    protected void layout(int width, int height) {
        if (isFocus()) {
            setExtent(width, playBkgrnd.getHeight());
        }
        else {
            setExtent(width, listBkgrnd.getHeight());
        }

    }

    protected void paint(Graphics graphics) {
        if (isFocus()) {
            // draw selected item
        }
        else {
            // draw unselected item
        }
    }

}

List fields on BlackBerry assume that all rows are the same height.

To get the kind of effect you want, use a bunch of selectable fields in a VerticalFieldManager, you'll get a similar effect to a ListField. Be sure to make your items focusable, and call updateLayout whenever they gain or lose focus, then in your layout method, set the field's height according to whether or not it's focused. Something like the following outline:

public class CustomListFieldItem extends Field {

    public boolean isFocusable() {
        return true;
    }

    protected void onFocus(int direction) {
        super.onFocus(direction);
        updateLayout();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        updateLayout();
    }

    protected void layout(int width, int height) {
        if (isFocus()) {
            setExtent(width, playBkgrnd.getHeight());
        }
        else {
            setExtent(width, listBkgrnd.getHeight());
        }

    }

    protected void paint(Graphics graphics) {
        if (isFocus()) {
            // draw selected item
        }
        else {
            // draw unselected item
        }
    }

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