0

在此处输入图像描述我正在尝试在水平管理器中显示事件,我有多个事件说现在我有 10 个事件,我想在单行中显示两个事件,创建 5 个水平管理器来显示其余 10 个事件。我能够显示一个使用下面的代码片段在单行中的事件,如何编辑下面的代码片段以在一行中获取两个事件,这里将事件添加到标签字段。

VerticalFieldManager vfm = new VerticalFieldManager();
        int allDayVectorSize = allDayVector.size();
        horizontalFieldManager_isAllDay = new HorizontalFieldManager[allDayVectorSize];
        allDayLabel = new LabelField[allDayVectorSize];
        row_height = 90;
        int j = 0;
        int row_count = 0;

        if (allDayVectorSize != 0) {
            for (int i = 0; i < allDayVectorSize; i++) {
                final String allEvent = (String) allDayVector.elementAt(i);
                horizontalFieldManager_isAllDay[row_count] = new HorizontalFieldManager(
                        Manager.FOCUSABLE | Manager.HORIZONTAL_SCROLL) {

                    protected boolean navigationClick(int status, int time) {
                        Field field = getFieldWithFocus();

                        Vector data = getData(listEvent);

                        if (allEvent != null && allEvent != "") {
                            System.out.println("Currentdata in if" + allEvent);
                            UiApplication.getUiApplication().pushScreen(
                                    new EventScreen(data, allEvent, ""));
                        }
                        return super.navigationClick(status, time);
                    }

                    protected boolean keyChar(char key, int status, int time) {
                        Field field = getFieldWithFocus();

                        return super.keyChar(key, status, time);
                    }

                    protected void sublayout(int maxWidth, int maxHeight) {
                        int displayWidth = Display.getWidth();
                        int displayHeight = 30;
                        super.sublayout(displayWidth, displayHeight);
                        setExtent(displayWidth, displayHeight);
                    }
                };
                horizontalFieldManager_isAllDay[row_count].setPadding(2, 2, 2,
                        2);
                allDayLabel[row_count] = new LabelField(allEvent,
                        LabelField.FOCUSABLE) {

                    protected void layout(int maxWidth, int maxHeight) {

                        int displayWidth = (int) (Display.getWidth() / 2);
                        int displayHeight = maxHeight;

                        super.layout(displayWidth, displayHeight);
                        setExtent(displayWidth, displayHeight);
                    }

                };

                // allDayLabel[row_count].setPadding(5, 0, 0, 2);
                final ImageButtonField alarmBitmapField2 = new ImageButtonField(
                        "", Field.FOCUSABLE, "ringtone.png", "ringtone.png",
                        0x9cbe95);
                horizontalFieldManager_isAllDay[row_count]
                        .add(alarmBitmapField2);
                horizontalFieldManager_isAllDay[row_count]
                        .add(allDayLabel[row_count]);
                vfm.add(horizontalFieldManager_isAllDay[row_count]);
                vfm.add(new SeparatorField());
            }
        }
4

1 回答 1

0
VerticalFieldManager vfm = new VerticalFieldManager();
        int allDayVectorSize = allDayVector.size();
        int hfmSize=(allDayVectorSize %2 ==0)allDayVectorSize/2:allDayVectorSize +1;
        horizontalFieldManager_isAllDay = new HorizontalFieldManager[hfmSize];
        allDayLabel = new LabelField[allDayVectorSize];
        row_height = 90;
        int j = 0;

        if (allDayVectorSize != 0) {
            for (int i = 0; i < hfmSize; i++) {

                horizontalFieldManager_isAllDay[i] = new HorizontalFieldManager(
                        Manager.FOCUSABLE | Manager.HORIZONTAL_SCROLL|Manager.USE_ALL_WIDTH) {

                    protected boolean navigationClick(int status, int time) {
                        Field field = getFieldWithFocus();

                        Vector data = getData(listEvent);

                        if (allEvent != null && allEvent != "") {
                            System.out.println("Currentdata in if" + allEvent);
                            UiApplication.getUiApplication().pushScreen(
                                    new EventScreen(data, allEvent, ""));
                        }
                        return super.navigationClick(status, time);
                    }

                    protected boolean keyChar(char key, int status, int time) {
                        Field field = getFieldWithFocus();

                        return super.keyChar(key, status, time);
                    }

                    protected void sublayout(int maxWidth, int maxHeight) {
                        int displayWidth = Display.getWidth();
                        int displayHeight = 30;
                        super.sublayout(displayWidth, displayHeight);
                        setExtent(displayWidth, displayHeight);
                    }
                };
                horizontalFieldManager_isAllDay[i].setPadding(2, 2, 2,
                        2);
                String allEvent = (String) allDayVector.elementAt(i*2);
                allDayLabel[i*2] = new LabelField(allEvent,
                        LabelField.FOCUSABLE) {

                    protected void layout(int maxWidth, int maxHeight) {

                        int displayWidth = (int) (Display.getWidth() / 2);
                        int displayHeight = maxHeight;

                        super.layout(displayWidth, displayHeight);
                        setExtent(displayWidth, displayHeight);
                    }

                };



                // allDayLabel[row_count].setPadding(5, 0, 0, 2);
                final ImageButtonField alarmBitmapField2 = new ImageButtonField(
                        "", Field.FOCUSABLE, "ringtone.png", "ringtone.png",
                        0x9cbe95);
                horizontalFieldManager_isAllDay[i]
                        .add(alarmBitmapField2);
                horizontalFieldManager_isAllDay[i]
                        .add(allDayLabel[i*2]);
                if(i*2+1<allDayVectorSize)
                {
                       allEvent = (String) allDayVector.elementAt(i*2+1);
                       allDayLabel[i*2] = new LabelField(allEvent,
                       LabelField.FOCUSABLE) {

                              protected void layout(int maxWidth, int maxHeight) {

                                  int displayWidth = (int) (Display.getWidth() / 2);
                                  int displayHeight = maxHeight;

                                  super.layout(displayWidth, displayHeight);
                                  setExtent(displayWidth, displayHeight);
                             }

                         };

                         horizontalFieldManager_isAllDay[i]
                        .add(allDayLabel[i*2+1]);
                   }
                vfm.add(horizontalFieldManager_isAllDay[row_count]);
                vfm.add(new SeparatorField());
            }
        }
于 2012-04-24T06:07:41.357 回答