设置Autocompletefield rowheight

时间:2012-05-11 01:55:24

标签: blackberry java-me blackberry-jde

screenshoot

我正在使用drawListRow重新绘制自动完成字段,但是我无法设置它的字段高度,这是我的代码:

autoCustomer = new AutoCompleteField(custList, style){
        public void drawListRow(ListField clistField, Graphics g,
                int index, int y, int width) {

                BasicFilteredListResult result = (BasicFilteredListResult) 
                        autoCustomer.get(clistField, index);//);
                if (result == null)
                    return;
                    String[] stringArray = parseMessage(result._object.toString(), Font.getDefault().derive(Font.PLAIN),fontSize, width-30);
                    int i;
                    int yCoord = 0;
                    int xCoord = 0;
                    //int rowHeight = (stringArray.length * fontHeight)+3;
                    clistField.setRowHeight((stringArray.length * fontHeight)+3); //already did this, but it won't work
                    System.out.println(stringArray.length);
                    g.setFont( Font.getDefault().derive(Font.PLAIN,fontSize,Ui.UNITS_px));
                    for(i = 0;i<stringArray.length;i++){
                        yCoord = y + (fontHeight*(i));
                        if(i>0)
                            xCoord = 20;       
                        g.drawText(stringArray[i].trim() , xCoord, yCoord, (DrawStyle.LEFT | DrawStyle.ELLIPSIS | DrawStyle.TOP ),  width-20);
                    }

        }

如何使用此自动完成方式设置正确的行高?

1 个答案:

答案 0 :(得分:1)

enter image description here

我无意中找到了答案,第一个参数是列表的索引,第二个参数是高度。 文档没有提到这一点,我只在eclipse中的类文档中找到了setRowHeight(int arg0,int arg1)。 解决方案很简单

clistField.setRowHeight(index,(stringArray.length * fontHeight)+3);