使用scroll在VerticalFieldManager中添加ListField

时间:2012-07-04 17:54:09

标签: blackberry

我可以使用滚动条件向ListField添加VerticalFieldManager吗?这样我就可以滚动ListFieldVertcalFieldManager

这里是发布代码的。抱歉,我发布了经理,无法发布整个代码。

mainManager = new CustomVerticalFieldManager(Display.getWidth(),
                Display.getHeight(), backgroundBitmap,
                Manager.NO_VERTICAL_SCROLL
                        | HorizontalFieldManager.USE_ALL_WIDTH
                        | Manager.FIELD_HCENTER) {

            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(Display.getWidth(), Display.getHeight());
                setExtent(Display.getWidth(), Display.getHeight());

                setPositionChild(middleManager, 5,
                        (headerManager.getContentHeight() + 30));
                setPositionChild(sliderBitmapField, 20, 37);

                setPositionChild(treeManager, 10,
                        (30 + middleManager.getExtent().height + headerManager
                                .getContentHeight()));

                setPositionChild(totalFareLabel, 20, Display.getHeight() - 60);

                setPositionChild(
                        footerManager,
                        ((Display.getWidth() / 2) - (footerManager.getWidth() / 2)),
                        Display.getHeight() - (footerManager.getHeight() + 3));




middleManager = new CustomVerticalFieldManager(Display.getWidth() - 20,
                90, Manager.NO_VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR)

        {
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(Display.getWidth() - 20, 90);

                setExtent(Display.getWidth() - 20, 90);

                setPositionChild(labelManager, 3, 5);
                setPositionChild(labelDescription, 8,
                        labelManager.getHeight() + 5);
                setPositionChild(lablelDepart, 8, labelManager.getHeight()
                        + labelDescription.getHeight() + 10);

            }


treeManager = new CustomVerticalFieldManager( Manager.USE_ALL_WIDTH | Field.FIELD_HCENTER | Manager.VERTICAL_SCROLL) {

            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(
                        Display.getWidth() - 20, 
                        Display.getHeight()
                                - (104 + middleManager.getHeight() + headerManager
                                        .getHeight()) -100);
                setExtent(
                        Display.getWidth() - 20, 
                        Display.getHeight()
                                - (104 + middleManager.getHeight() + headerManager
                                        .getHeight()) -100);
            }



CustomListField lF = new CustomListField(listData);
                treeManager.add(lF);

以下是CustomListField

public class CustomListField extends ListField implements ListFieldCallback {

    private Vector _listData;

    private int _MAX_ROW_HEIGHT = 30;
    private boolean isFocused = false;

    public CustomListField(Vector data) {

        _listData = data;

        setSize(_listData.size());

        setSearchable(true);

        setCallback(this);

        setRowHeight(_MAX_ROW_HEIGHT);

    }

    protected void drawFocus(Graphics graphics, boolean on) {

        XYRect rect = new XYRect();

        getFocusRect(rect);
        boolean oldDrawStyleFocus = graphics
                .isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS);
        try {
            if (on) {

                graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
                int oldColour = graphics.getColor();
                try {
                    graphics.setColor(0x63003D);
                    graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
                    isFocused = true;
                } finally {
                    graphics.setColor(oldColour);
                }

                drawListRow(this, graphics, getSelectedIndex(), rect.y,
                        rect.width);
            }

        } finally {
            graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS,
                    oldDrawStyleFocus);
        }
    }

    public int moveFocus(int amount, int status, int time) {

        this.invalidate(this.getSelectedIndex());

        return super.moveFocus(amount, status, time);

    }

    public void onFocus(int direction) {

        super.onFocus(direction);

    }

    protected void onUnFocus() {

        this.invalidate(this.getSelectedIndex());

    }

    public void refresh() {

        this.getManager().invalidate();

    }

    public void drawListRow(ListField listField, Graphics graphics, int index,
            int y, int w) {

        UpsellFlightListDTO upsellListDTO = (UpsellFlightListDTO) _listData
        .elementAt(index);

        graphics.setGlobalAlpha(255);

        graphics.setFont(Font.getDefault().getFontFamily()
                .getFont(Font.PLAIN, 12));

        final int margin = 5;

        String listHeading = "";//listRander.getListTitle();
        String listDesc = "";//listRander.getListDesc();
        graphics.setColor(Color.GRAY);

        graphics.drawRect(0, y, w, _MAX_ROW_HEIGHT);


        graphics.setColor(Color.BLACK);

//      graphics.setFont(Font.getDefault());

        if (isFocused) {
            graphics.setColor(Color.WHITE);
            isFocused = false;
        } else {
            graphics.setColor(Color.BLACK);
        }

        listHeading = upsellListDTO.getFlightNo()[0]+"\t"+upsellListDTO.getToFromCode()[0]
                      +"\t"+ upsellListDTO.getDepArrTime()[0] + "\t" + upsellListDTO.getStops()[0];

        graphics.drawText(listHeading, 10, y
                + margin);
        listDesc = "Flight Duration:- "+upsellListDTO.getFlightDuration()[0] + "\t \t Fare:- " + upsellListDTO.getFare();

        graphics.drawText(listDesc, 10, y + margin + 12);
    }

    public Object get(ListField listField, int index) {

        String rowString = (String) _listData.elementAt(index);

        return rowString;

    }

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

        for (Enumeration e = _listData.elements(); e.hasMoreElements();) {

            String rowString = (String) e.nextElement();

            if (rowString.startsWith(prefix)) {

                return _listData.indexOf(rowString);

            }

        }

        return 0;

    }

    public int getPreferredWidth(ListField listField) {

        return 3 * listField.getRowHeight();

    }

    /*
     * protected boolean trackwheelClick (int status, int time) {
     * 
     * invalidate(getSelectedIndex());
     * 
     * Dialog.alert(" U have selected :" + getSelectedIndex());
     * 
     * return super.trackwheelClick(status, time);
     * 
     * }
     */

    private ColoredLabelField getCustomedLabel(String text, int color, int size, int style, int align){



        return null;
    }

}

0 个答案:

没有答案