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;
}
}
謝謝你...它的工作原理(對不起的IAM英語不好)。 –