【问题标题】:How to customize listfield items?如何自定义列表字段项?
【发布时间】:2010-07-16 23:46:13
【问题描述】:

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

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

_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));
    }
}

【问题讨论】:

    标签: blackberry blackberry-storm


    【解决方案1】:

    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
            }
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 2012-08-28
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多