Search code examples
blackberrylistfield

How to override downloaded image with default image to black berry list field


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);

}

Solution

  • 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, just invalidate() the ListField and it will draw the newly downloaded image.