2013-02-14 15 views
0

我有一個ListField行爲怪異,我沒有很多的BB開發經驗,但在互聯網上搜索很多,我結束了以下。我用this tutorial做了很多ListField的東西。ListField select rowbreak其他行的高度

這是截圖,當我打開屏幕的第一時間,不要做任何事情:

Screen A

這是當我向下滾動一個截圖,這對所有的效果相同田:

enter image description here

這是我實現調整我的需求基於上面的教程中提到:

private Bitmap p1; 
TableRowManager row; 
Vector rows; 

public ImageListField(List list) { 
    /* Init & Declaration */ 
    setEmptyString("This ListField has No Data", DrawStyle.HCENTER); 
    setCallback(this); 
    setRowHeight(50); 
    Font.getDefault(); 
    p1 = Bitmap.getBitmapResource("no-image.png"); 
    rows = new Vector(); 
    for (int x = 0; x < list.size(); ++x) { 
     Event e = (Event)list.getAt(x); 

     row = new TableRowManager(); 

     BitmapField myImageField = new BitmapField(p1); 
     row.add(myImageField); 
     row.add(new LabelField(e.Name, 
       DrawStyle.ELLIPSIS | FOCUSABLE){ 

      public void paint(Graphics g) { 
       g.setBackgroundColor(Color.BLACK); 
       g.fillRect(0, 0, getWidth(), getHeight()); 
       g.setColor(Color.WHITE); 
       g.clear(); 
       super.paint(g); 
      } 

     }); 

     if(e.DateFrom.compareTo(e.DateTo) == 0) 
     { 
      row.add(new LabelField(e.DateFrom, 
        DrawStyle.ELLIPSIS | FOCUSABLE){ 

       public void paint(Graphics g) { 
        g.setBackgroundColor(Color.BLACK); 
        g.fillRect(0, 0, getWidth(), getHeight()); 
        g.setColor(Color.WHITE); 
        g.clear(); 
        super.paint(g); 
       } 

      }); 
     } 
     else 
     { 
      row.add(new LabelField(e.DateFrom + " - " + e.DateTo, 
        DrawStyle.ELLIPSIS | FOCUSABLE){ 

       public void paint(Graphics g) { 
        g.setBackgroundColor(Color.BLACK); 
        g.fillRect(0, 0, getWidth(), getHeight()); 
        g.setColor(Color.WHITE); 
        g.clear(); 
        super.paint(g); 
       } 

      }); 
     } 

     if(e.TimeFrom.compareTo(e.TimeTo) == 0) 
     { 
      row.add(new LabelField(e.TimeFrom, 
        DrawStyle.ELLIPSIS | FOCUSABLE){ 

       public void paint(Graphics g) { 
        g.setBackgroundColor(Color.BLACK); 
        g.fillRect(0, 0, getWidth(), getHeight()); 
        g.setColor(Color.WHITE); 
        g.clear(); 
        super.paint(g); 
       } 

      }); 
     } 
     else 
     { 
      row.add(new LabelField(e.TimeFrom + " - " + e.TimeTo, 
        DrawStyle.ELLIPSIS | FOCUSABLE){ 

       public void paint(Graphics g) { 
        g.setBackgroundColor(Color.BLACK); 
        g.fillRect(0, 0, getWidth(), getHeight()); 
        g.setColor(Color.WHITE); 
        g.clear(); 
        super.paint(g); 
       } 

      }); 
     } 

     row.add(new LabelField(e.Address, 
       DrawStyle.ELLIPSIS | FOCUSABLE){ 

      public void paint(Graphics g) { 
       g.setBackgroundColor(Color.BLACK); 
       g.fillRect(0, 0, getWidth(), getHeight()); 
       g.setColor(Color.WHITE); 
       g.clear(); 
       super.paint(g); 
      } 

     }); 

     row.add(new LabelField("R " + e.EntranceFee, 
       DrawStyle.ELLIPSIS | FOCUSABLE){ 

      public void paint(Graphics g) { 
       g.setBackgroundColor(Color.BLACK); 
       g.fillRect(0, 0, getWidth(), getHeight()); 
       g.setColor(Color.WHITE); 
       g.clear(); 
       super.paint(g); 
      } 

     }); 

     rows.addElement(row); 
    } 
    setSize(rows.size()); 
} 

public void drawListRow(ListField listField, Graphics graphics, int index, 
     int y, int width) { 
    // TODO Auto-generated method stub 
    ImageListField list = (ImageListField) listField; 
    TableRowManager rowManager = (TableRowManager) list.rows 
      .elementAt(index); 
    rowManager.drawRow(graphics, 0, y, width, 119); 
} 

public Object get(ListField listField, int index) { 
    // TODO Auto-generated method stub 
    return rows.elementAt(index).toString(); 
} 

public int getPreferredWidth(ListField listField) { 
    // TODO Auto-generated method stub 
    return Graphics.getScreenWidth(); 
} 

public int getRowHeight() { 
    // TODO Auto-generated method stub 
    return 119; 
} 

public int getRowHeight(int arg0) { 
    // TODO Auto-generated method stub 
    return 119; 
} 

public int indexOfList(ListField listField, String prefix, int start) { 
    // TODO Auto-generated method stub 
    return -1; 
} 

protected boolean trackwheelClick(int status, int time) { 
    int index = getSelectedIndex(); 
    Dialog.inform(Integer.toString(index)); 
    return true; 
} 

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

    // Causes the fields within this row manager to be layed out then 
    // painted. 
    public void drawRow(Graphics g, int x, int y, int width, int height) { 
     // Arrange the cell fields within this row manager. 
     layout(width, height); 
     // Place this row manager within its enclosing list. 
     setPosition(x, y); 
     // Apply a translating/clipping transformation to the graphics 
     // context so that this row paints in the right area. 
     g.pushRegion(getExtent()); 
     // Paint this manager's controlled fields. 
     subpaint(g); 
     g.setColor(0xFF0000); 
     g.drawLine(0, height - 1, getPreferredWidth(), height - 1); 
     g.drawLine(40, 0, 40, getPreferredHeight()); 
     // Restore the graphics context. 
     g.popContext(); 
    } 

    // Arrages this manager's controlled fields from left to right within 
    // the enclosing table's columns. 
    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, 75, 75); 
     setPositionChild(field, 5, 5); 
     // set the task name label field 
     field = getField(1); 
     layoutChild(field, preferredWidth, fontHeight + 2); 
     setPositionChild(field, 85, 5); 
     // set the list name label field 
     field = getField(2); 
     layoutChild(field, preferredWidth, fontHeight + 2); 
     setPositionChild(field, 85, fontHeight + 6 + 5); 
     // set the due time name label field 
     field = getField(3); 
     layoutChild(field, preferredWidth, fontHeight + 2); 
     setPositionChild(field, 100, fontHeight + fontHeight + 8 + 5); 

     field = getField(4); 
     layoutChild(field, preferredWidth, fontHeight + 2); 
     setPositionChild(field, 100, fontHeight + fontHeight + fontHeight + 10 + 5); 

     field = getField(5); 
     layoutChild(field, preferredWidth, fontHeight + 2); 
     setPositionChild(field, 100, fontHeight + fontHeight + fontHeight + fontHeight + 12 + 5); 

     setExtent(preferredWidth, getPreferredHeight()); 
    } 

    // The preferred width of a row is defined by the list renderer. 
    public int getPreferredWidth() { 
     return Graphics.getScreenWidth(); 
    } 

    // The preferred height of a row is the "row height" as defined in the 
    // enclosing list. 
    public int getPreferredHeight() { 
     return 119;// getRowHeight(); 
    } 


} 

任何有關改變行高和位置的建議將不勝感激。

順便說一句,這是在模擬器。

回答

2

嘗試設置setRowHeight(119);而不是setRowHeight(50);。不知道它是否有幫助,因爲它不是在發佈的代碼中通常應用/使用ListField

+0

感謝工作像一個魅力 – Armand 2013-02-15 06:17:25

相關問題