我是黑莓编程的新手。我正在尝试做一个可点击的列表视图,就像在音乐播放器中一样,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;
}
}