它只显示文字,但不显示图像

时间:2011-02-09 10:17:56

标签: blackberry

我开发了如下代码。在这里我使用了listfield,一个bitmapfield和一个标签字段,当我运行它时,它只显示列表字段行上的文本,但不显示图像 我不知道我错在哪里,所以,任何人都可以帮我知道我错在哪里 谢谢你的帮助

class TaskListField extends MainScreen implements ListFieldCallback {
         private Vector rows;
         private Bitmap p1;
ListField list;
         TableRowManager row;
         public TaskListField() {
          super();
          list=new ListField() {

              protected void drawFocus(Graphics graphics, boolean on) {
              }

};
          list.setRowHeight(40);
          list.setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
          list.setCallback(this);

          p1 = Bitmap.getBitmapResource("res/images/10.png");
 rows = new Vector();

          for (int x = 1; x < 13; x++) {
            row = new TableRowManager();
             LabelField task = new LabelField("" + String.valueOf(x),
             DrawStyle.ELLIPSIS);
   row.add(task);
           row.add(new BitmapField(p1));
  rows.addElement(row);
          }
          list.setSize(rows.size());
add(list);
         }

         // ListFieldCallback Implementation
         public void drawListRow(ListField listField, Graphics g, int index, int y,
           int width) {

          TableRowManager rowManager = (TableRowManager) rows
            .elementAt(index);
          rowManager.drawRow(g, 0, y, width, list.getRowHeight());
         }

         private class TableRowManager extends Manager {
          public TableRowManager() {
           super(0);
          }
  public void drawRow(Graphics g, int x, int y, int width, int height) {

           layout(width, height);


           setPosition(x, y);


           g.pushRegion(getExtent());

           // Paint this manager's controlled fields.
           subpaint(g);

           g.setColor(0x00CACACA);
           g.drawLine(0, 0, getPreferredWidth(), 0);

           // Restore the graphics context.
           g.popContext();
          }


          protected void sublayout(int width, int height) {

           int preferredWidth = getPreferredWidth();


           Field field = getField(0);
           layoutChild(field, 30, 30);
           setPositionChild(field, 0, 0);


          field = getField(1);
           layoutChild(field, 40, 25);
           setPositionChild(field, 120, 10);
  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 list.getRowHeight();
          }
         }

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

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

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

3 个答案:

答案 0 :(得分:1)

放置图片路径时没有必要

p1 = Bitmap.getBitmapResource (" res/images/10.png ");

只需要

p1 = Bitmap.getBitmapResource (" 10.png ");

答案 1 :(得分:0)

你确定位图不是空的吗?我先检查一下 - 也许它找不到资源。

答案 2 :(得分:0)

LabelField是否可以占据屏幕的整个宽度(在某些情况下会这样做)?如果仅设置图像而不设置标签,图像是否会显示?