如何使用 Array、List、HashMap 或 HashSet - 创建 BitmapFields 的长列表? (爪哇、黑莓)

发布于 2024-11-16 17:46:37 字数 523 浏览 4 评论 0原文

我需要:1)创建 BitmapFields 的列表,2)将它们添加到屏幕上。由于列表很长,我想使用一些简短的自动化方法,如 Loop 或类似的方法:

while (i < 1000)
 {
 i = i + 1;
 myBitmapField[i].setBitmap(Bitmap.getBitmapResource("picture" + i+ ".png"));
 myVerticalFieldManager.add(_myBitmapField[i]);
 }

但似乎我无法将索引 i 分配给 BitmapField myBitmapField[i],仅是文件本身的名称。

那么如何创建一长串 BitmapFields 列表?我可以使用 List、Array、HashMap 或 HashSet 来实现此目的吗?欢迎举个例子。多谢! (黑莓、爪哇)

I need to: 1) create long list of BitmapFields and 2) add them to the screen. Since list is long I want to use some short automated method like Loop or similar:

while (i < 1000)
 {
 i = i + 1;
 myBitmapField[i].setBitmap(Bitmap.getBitmapResource("picture" + i+ ".png"));
 myVerticalFieldManager.add(_myBitmapField[i]);
 }

But it seems that I cannot assign a index i to a name of BitmapField myBitmapField[i], only to a name of the file itself.

So how can I create a long list of BitmapFields ? Can i use List, Array, HashMap, or HashSet for this purpose? An example welcome. Thanks a lot! (Blackberry, Java)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

四叶草在未来唯美盛开 2024-11-23 17:46:37

如果您收到该错误,则仅意味着 myBitmapField 未声明为数组类型。您需要将其声明为数组,例如:

BitmapField[] myBitmapField = new BitmapField[1000];
for (int i = 0; i < 1000; i++) {
    myBitmapField[i] = new BitmapField();
}

原则上您可以使用列出的任何数据类型,但只能使用 [...] 语法对数组进行索引。您只需更改声明初始化即可使用您想要的任何数据类型。如果您使用不支持索引的类型,则必须更改索引才能对您选择的数据类型使用 .get 方法。但我不确定为什么你想要使用数组以外的任何东西......

此时你不妨将上述循环与现有循环结合起来,这样你就只有一个循环。

另外,如果要显示 1000 张图像,性能可能会糟糕。 BlackBerry 无法处理列表中任何类型的 1000 个字段,而且图像可能相当重量级。在某些设备上加载甚至可能需要很长时间,以至于黑莓会认为您的应用程序挂起并终止它。更不用说从用户界面的角度来看,在一个小移动屏幕上显示如此多的项目并不是很好,因为没有用户能够在合理的时间范围内导航到所有这些项目。

If you're getting that error, that just means that myBitmapField isn't declared as an array type. You'll want to declare it as an array, e.g:

BitmapField[] myBitmapField = new BitmapField[1000];
for (int i = 0; i < 1000; i++) {
    myBitmapField[i] = new BitmapField();
}

You could in principle use any of the data types you listed, though only an array can be indexed with the [...] syntax. You just have to change the declaration initialization to use whatever data type you want. And if you use a type that doesn't support indexes you'll have to change your index to use the .get method on the data type you choose. But I'm not sure why you'd want to use anything other than an array...

And at that point you might as well combine the above loop with your existing loop, so that you only have one loop.

Also, if you have 1000 images being displayed, you will probably have horrible performance. BlackBerry has trouble dealing with 1000 fields of any type in a list, and images can be fairly heavyweight. It may even take so long to load on some devices that the BlackBerry will think your app is hanging and terminate it. Not to mention that it isn't very good from a UI perspective to have so many items on a small mobile screen, since no user would be able to navigate to all of them in a reasonable timeframe.

楠木可依 2024-11-23 17:46:37

我试过你的方法,似乎也不适合我。试试这个:

private pics = new Vector();

for(int i = 0; i < 1000; i++{

    BitmapField temp = new BitmapField();
    pics.addElement(temp);
    ((BitmapField)pics.elementAt(i)).setBitmap(Bitmap.getBitmapResource("picture" + i + ".png"));
    add((BitmapField)pics.elementAt(i));

}

我也同意@Ted 关于 1000 个字段的观点。祝你好运,请告诉我们。

I tried your way, doesn't seem to for for me either. try this:

private pics = new Vector();

for(int i = 0; i < 1000; i++{

    BitmapField temp = new BitmapField();
    pics.addElement(temp);
    ((BitmapField)pics.elementAt(i)).setBitmap(Bitmap.getBitmapResource("picture" + i + ".png"));
    add((BitmapField)pics.elementAt(i));

}

Also i agree with @Ted about the 1000 fields. good luck, let us know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文