TablelayoutManager,如何创建自定义List?

时间:2013-06-18 20:13:32

标签: blackberry tablelayout

我是BlackBerry编程的新手。我正在尝试做一个可点击的列表视图,比如在音乐播放器中,左边是Bitmap,标题和副标题。我按此屏幕时出错:

  

“字段已添加到管理器,因为它已经是父级。”

这是我的代码:

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 个答案:

答案 0 :(得分:1)

您要将logo添加到innerTable outerTable

A Field can only be added to one Manager (container) at once。将字段添加到第二个管理器会产生错误:

  

字段已添加到管理器,因为它已经是父级。

此情况下的TableLayoutManagerlogo字段的

只需删除对add(logo)的一次通话,例如:

    innerTable.add(logo);