2013-06-18 88 views
1

我是BlackBerry编程新手。我试图做一个可点击的列表视图,就像在音乐播放器中一样,左边有Bitmap,标题和副标题。我有一个错误,当我把这个画面:TablelayoutManager,如何创建自定义列表?

"Field added to manager while it is already parented."

这里是我的代码:

public class Tab_Main extends MainScreen 
{ 
    public Tab_Main() 
    { 
     Bitmap bitmap1 = Bitmap.getBitmapResource("logo.png"); 
     Bitmap bitmap2 = Bitmap.getBitmapResource("logo.png"); 
     bitmap1 = resizeBitmap(bitmap1, 55, 55);   
     bitmap2 = resizeBitmap(bitmap2, 55, 55); 
     LabelField t_text = new LabelField("Massala SoftWares"); 
     LabelField m_text = new LabelField("Hello World"); 
     BitmapField logo = new BitmapField(bitmap2); 
     TableLayoutManager outerTable = new TableLayoutManager(new int[] 
       { 
       TableLayoutManager.USE_PREFERRED_SIZE, 
       TableLayoutManager.SPLIT_REMAINING_WIDTH 
       },0); 
     TableLayoutManager innerTable = new TableLayoutManager(new int[] 
       { 
       TableLayoutManager. USE_PREFERRED_SIZE, 
       TableLayoutManager.USE_PREFERRED_SIZE 
       }, Manager.USE_ALL_WIDTH); 

     innerTable.add(t_text); 
     innerTable.add(m_text); 
     innerTable.add(new LabelField("Description")); 
     innerTable.add(new LabelField("Description Link")); 
     innerTable.add(new LabelField("Rating")); 
     innerTable.add(logo); 

     outerTable.add(logo); 
     outerTable.add(innerTable); 

     super.add(outerTable); 
    } 

    public static Bitmap resizeBitmap(Bitmap image, int width, int height) 
    { 
     int imageWidth = image.getWidth(); 
     int imageHeight = image.getHeight(); 

     // Need an array (for RGB, with the size of original image) 
     int rgb[] = new int[imageWidth * imageHeight]; 

     // Get the RGB array of image into "rgb" 
     image.getARGB(rgb, 0, imageWidth, 0, 0, imageWidth, imageHeight); 

     // Call to our function and obtain rgb2 
     int rgb2[] = rescaleArray(rgb, imageWidth, imageHeight, width, height); 

     // Create an image with that RGB array 
     Bitmap temp2 = new Bitmap(width, height); 

     temp2.setARGB(rgb2, 0, width, 0, 0, width, height); 

     return temp2; 
    } 

    private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2) 
    { 
     int out[] = new int[x2*y2]; 

     for (int yy = 0; yy < y2; yy++) 
     { 
      int dy = yy * y/y2; 
      for (int xx = 0; xx < x2; xx++) 
      { 
       int dx = xx * x/x2; 
       out[(x2 * yy) + xx] = ini[(x * dy) + dx]; 
      } 
     } 
     return out; 
    } 
} 

回答

1

要添加logo到这两个innerTableouterTable

A Field can only be added to one Manager (container) at once。添加一个字段添加到第二个经理是什么产生错误:

Field added to manager while it is already parented.

在这种情况下的TableLayoutManagerlogo

只需拆除一个呼叫add(logo),例如:

innerTable.add(logo); 
+0

谢谢你...它的工作原理(对不起的IAM英语不好)。 –

相关问题