2010-07-16 98 views
1

我是黑莓开发新手。我的应用程序包含五个列表项,每个项目都有字符串。我的要求是当选择一个单元格时应该放大,其他项目自动调整空格。 我为列表项目选择了两种类型的图像,一种用于常规视图,另一种用于在用户点击高于以前的高度时显示选定的项目。如何自定义listfield项目?

但问题是,当我选择一个项目时,它正在放大和重叠在下一个项目上,并没有显示完整的项目,并没有调整它们之间的空间。 任何人都可以给我这个解决方案。我使用下面的代码段....

_listField.setCallback(this); 
    _listField.setRowHeight(45); 
    _listField.setChangeListener(this); 

公共无效drawListRow(ListField为arg0,图形图形,INT指数, INT Y,INT宽度){

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

回答

2

列表有关黑莓字段假定所有行都是相同的高度。

要获得您想要的效果,请使用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 
     } 
    } 

}