Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建与BlackBerry facebook相同样式的列表字段?_Blackberry_User Interface - Fatal编程技术网

如何创建与BlackBerry facebook相同样式的列表字段?

如何创建与BlackBerry facebook相同样式的列表字段?,blackberry,user-interface,Blackberry,User Interface,如何创建与Black Berry facebook风格相同的列表字段? RIM列表字段只包含文本,我想创建一个列表字段,它可以包含其他字段,如图像、文本区域和href链接 我成功地创建了它,它工作得很好,但是列表项中的字段从未获得焦点,你知道怎么做吗 public class RichListField extends ListField implements ListFieldCallback { private Vector rows; public RichListField(Stri

如何创建与Black Berry facebook风格相同的列表字段? RIM列表字段只包含文本,我想创建一个列表字段,它可以包含其他字段,如图像、文本区域和href链接

我成功地创建了它,它工作得很好,但是列表项中的字段从未获得焦点,你知道怎么做吗

public class RichListField extends ListField implements ListFieldCallback {
private Vector rows;


public RichListField(String emtpyString, RichListItem[] items) {
    super(0, ListField.MULTI_SELECT);
    setRowHeight(80);
    setEmptyString(emtpyString, DrawStyle.HCENTER);
    setCallback(this);

    rows = new Vector();

    for (int i = 0; i < items.length; i++) {
        TableRowManager row = new TableRowManager();

        row.add(new BitmapField(items[i].getBitmap()));

        LabelField itemLabel = new LabelField(items[i].getLabel(),
                DrawStyle.ELLIPSIS);
        // mark selected
        // itemLabel.setFont(Font.getDefault().derive(
        // Font.BOLD | Font.UNDERLINED));

        itemLabel.setFont(Font.getDefault().derive(Font.BOLD));
        row.add(itemLabel);

        // SET THE LIST Item description
        row.add(new LabelField(items[i].getDescription(),
                DrawStyle.ELLIPSIS) {
            protected void paint(Graphics graphics) {
                graphics.setColor(0x00878787);
                super.paint(graphics);
            }
        });


        row.add(items[i].getLink());
        rows.addElement(row);
    }
    setSize(rows.size());

}


public void drawListRow(ListField listField, Graphics g, int index, int y,
        int width) {
    RichListField list = (RichListField) listField;
    TableRowManager rowManager = (TableRowManager) list.rows
            .elementAt(index);
    rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}

private class TableRowManager extends Manager {
    public TableRowManager() {
        super(0);
    }


    public void drawRow(Graphics g, int x, int y, int width, int height) {
        // Arrange the cell fields within this row manager.
        layout(width, height);

        setPosition(x, y);


        g.pushRegion(getExtent());

        subpaint(g);

        g.setColor(0x00CACACA);
        g.drawLine(0, 0, getPreferredWidth(), 0);

        // Restore the graphics context.
        g.popContext();
    }



    protected void sublayout(int width, int height) {
        // set the size and position of each field.
        int fontHeight = Font.getDefault().getHeight();
        int preferredWidth = getPreferredWidth();

        // start with the Bitmap Field of the priority icon
        Field field = getField(0);
        layoutChild(field, 32, 32);
        setPositionChild(field, 0, 0);

        // set the   label field
        field = getField(1);
        layoutChild(field, preferredWidth - 16, fontHeight + 1);
        setPositionChild(field, 34, 3);

        // set the description label field
        field = getField(2);
        layoutChild(field, preferredWidth, fontHeight + 1);
        setPositionChild(field, 34, fontHeight + 6);

        // set the Href field
        field = getField(3);
        layoutChild(field, 150, fontHeight + 1);
        setPositionChild(field, preferredWidth - 152, fontHeight + 6);

        //To set the required dimensions for the field
        setExtent(preferredWidth, getPreferredHeight());
    }


    public int getPreferredWidth() {
        return Display.getWidth();
    }

    public int getPreferredHeight() {
        return getRowHeight();
    }
}

public Object get(ListField listField, int index) {

    return null;
}

public int getPreferredWidth(ListField listField) {

    return 0;
}

public int indexOfList(ListField listField, String prefix, int start) {

    return 0;
}

}

如果您只想在行具有焦点时更改颜色,则可以覆盖ListField.drawFocus():


当实现接口
ListFieldCallback
时,只需在
drawListRow
添加两行代码

if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) rowColor = Color.RED;
else rowColor = Color.GRAY

你需要更具体一些。您需要做哪些您不能使用本机列表字段的事情?发布屏幕截图和/或一些代码将帮助我们解决您的问题。
protected void drawFocus(Graphics graphics, boolean on) {
    if (on) {
        graphics.setColor(focusColor);
        graphics.setBackgroundColor(focusBackgroundColor);
        super.drawFocus(graphics, on);
        /**
          You may have to play with the call to super.drawFocus() depending on
          what it actually does. For example:
          super.drawFocus(graphics, false); 
          may work better. Or you may have to draw the field yourself.
        */
    }
}
if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) rowColor = Color.RED;
else rowColor = Color.GRAY