如何使用默认图像覆盖下载的图像到黑莓列表字段
从过去的两天开始,我正在用黑莓中的网络图像做列表字段,因为我是新的。 我正在显示带有一些默认图像的列表字段。当我从网络下载实际图像时,它无法替换默认图像。我使用一个线程一张一张地加载图像。但是图像没有正确覆盖默认图像。请帮助我。这是我的代码 的列表字段。
public void drawListRow(ListField listField,final Graphics graphics,int index,
final int y, int width)
{
this.graphics=graphics;
this.inde=index;
class ImageDowload extends Task
{
void doTask()
{
load=new DowloadImage(picture[inde]);
if(load.getData()!=null)
{
_bmap=load.getBitmap();
graphics.drawBitmap(3,y+7,placeholder.getWidth(), placeholder.getHeight(),_bmap, 0, 0);
}
}
}
taskWorker.addTask(new ImageDowload());
String text=(String) get(listField, index);
String pricedetails=price[index];
graphics.setColor(rgb);
graphics.setFont(Utility.getBigFont(DConfig.getFSize()+4));
graphics.drawBitmap(3,y+7,placeholder.getWidth(), placeholder.getHeight(),placeholder, 0, 0);
graphics.drawText(text,100,y+25);
graphics.drawText(pricedetails+" $",420,y+25);
graphics.drawLine(0, y+74, DConfig.disWidth, y+74);
}
From the past two days i am doing list field with web image in black berry,because i am new.
I am displaying list field with some default image.when i dowloaded the actual image from web it can't replacing on default image.I used one thread to load images one by one.But images are not overriding with default image properly.Please help me.Here is my code
of list field.
public void drawListRow(ListField listField,final Graphics graphics,int index,
final int y, int width)
{
this.graphics=graphics;
this.inde=index;
class ImageDowload extends Task
{
void doTask()
{
load=new DowloadImage(picture[inde]);
if(load.getData()!=null)
{
_bmap=load.getBitmap();
graphics.drawBitmap(3,y+7,placeholder.getWidth(), placeholder.getHeight(),_bmap, 0, 0);
}
}
}
taskWorker.addTask(new ImageDowload());
String text=(String) get(listField, index);
String pricedetails=price[index];
graphics.setColor(rgb);
graphics.setFont(Utility.getBigFont(DConfig.getFSize()+4));
graphics.drawBitmap(3,y+7,placeholder.getWidth(), placeholder.getHeight(),placeholder, 0, 0);
graphics.drawText(text,100,y+25);
graphics.drawText(pricedetails+" $",420,y+25);
graphics.drawLine(0, y+74, DConfig.disWidth, y+74);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对不想将请求放入
drawListRow()
中,因为每次需要重新绘制时它都会触发。只需在创建 ListField 时(或任何有意义的时间)开始下载所有图像即可。在您的
drawListRow()
中,当您去绘制位图时,检查下载的位图是否存在,以及是否绘制该位图,如果不绘制则默认绘制。现在,每个图像下载完成后,只需invalidate()
ListField 即可绘制新下载的图像。You definitely don't want to be putting your ask in the
drawListRow()
, as it's going to fire every time it has to repaint.Just start the downloading for all images when you create the ListField (or any time that makes sense). In your
drawListRow()
when you go to paint the Bitmap, check if the downloaded one exists, and if it does draw that, if not draw the default. Now as each image download is complete, justinvalidate()
the ListField and it will draw the newly downloaded image.