Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----
Accepted Solution

Images on screen in list updated only after scrolling on list row instead of automatically updating after each image is downloaded(image lazy loading)

1. I have started an image lazy loader to download images in drawListRow and passed the reference url of the image to be downloaded. 

2. After downloading the respective bitmap in the image lazy loader, I have invalidated the list(called using a reference of the mainscreen where images are to be drawn) using an event thread as follows:

	UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
        		_list.invalidate();
            }
        });

 But my images are updated on the screen only after I scroll on the list row.  I have also tried using _list.invalidate(index) for invalidating each row after the image is drawn for that particular row but it does not work and performs the same as _list.invalidate().

 I want the images to be updated without the scrolling and as soon as they are downloaded. How do I achieve this ?

Valuable inputs will be highly appreciated.  

 

UiApplication.getUiApplication().invokeLater(new Runnable() {            public void run() {        _list.invalidate();            }        });

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Images on screen in list updated only after scrolling on list row instead of automatically updating after each image is downloaded(image lazy loading)

use invokeAndWait instead of invokeLater and check whether it working or not?
Contributor
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: Images on screen in list updated only after scrolling on list row instead of automatically updating after each image is downloaded(image lazy loading)

Thank you. It's working but for some images I still have to scoll onn that particular list row for them to be updated

Developer
Posts: 19,618
Registered: ‎07-14-2008
My Device: Not Specified

Re: Images on screen in list updated only after scrolling on list row instead of automatically updating after each image is downloaded(image lazy loading)

[ Edited ]

The change from invokeLater to invokeAndWait will actually have made no difference as to whether the list is updated or not.  In fact I would not recommend using invokeAndWait, as this can lead to possibilities of deadlock with in the application. 

  

In fact, you do not need to run invalidate() on the Event Thread, and I would not recommend doing so using either invokeLater or invokeAndWait. 

 

And you should do what you originally did and invalidate the row that the image has been downloaded for.  This will make your processing more efficient - and it will only repaint the ListField row if that row was actually on display!

 

So replace the code that currently says something like this:

 

UiApplication.getUiApplication().invokeAndWait(new Runnable() {

 public void run() {

  _list.invalidate();

 }

});

 

with just this:

_list.invalidate(index);

 

The fact that invalidate(index) does not seem to work for you, will I suspect, be some processing in your code.  So put a break point in this line 

_list.invalidate(index);

 

and a break point in your drawListRow method.  Track an update to the image, and make sure that drawListRow() is subsequently invoked for that same index and correctly uses the newly downloaded image.

 

If you can track this right through (and I know this can be difficult because there are probably multiple downloads all going at the same time) I suspect you will find the problem.

 

The basic mechanism you are using works well. 

Contributor
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: Images on screen in list updated only after scrolling on list row instead of automatically updating after each image is downloaded(image lazy loading)

Thank you peter_strange. Yes what you have stated should work appropriately but on replacing invokelater with invokeandwait has worked. 

Developer
Posts: 19,618
Registered: ‎07-14-2008
My Device: Not Specified

Re: Images on screen in list updated only after scrolling on list row instead of automatically updating after each image is downloaded(image lazy loading)

Future readers of this Thread please be aware that the change from invokeLater to invokeAndWait should not have resolved a problem - if it did then in my opinion, there is another compensating problem elsewhere in the code.  Also be aware that in this specific case, neither invokeLater nor invokeAndWait should be needed.