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

Adobe AIR Development

Reply
Highlighted
Developer
Posts: 1,251
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C
Accepted Solution

Cell Renderer Madness - Renaun if you see this please chime in

Who needs March Madness when you can have Cell Renderer Madness ... 

 

I have a QNX list that can have items added to and deleted from it, and so it can grow beyond, and contract back into, the list's visible viewport.

I have a custom cell renderer that is similar to the cell renderer example in the RIM PlayBook dev guide.  It adds a check box to each item and is set up to allow multiple list items to be checked, while the list itself is set up for single selection.  The intent of this list is to allow certain actions on multiple items, and other actions only on a single item at a time.

In testing my code, I'm doing the following: I populate my list with enough test items to make it larger than the viewport, I scroll to the bottom of the list,  check off several items at the end of the list, and delete them with a delete handler function.  This results in items at the top of the list (which are not visible in the list's viewport at the time I do the delete) disappearing.  They still exist in the list's data provider, but it may be that when they scroll out of view, their renderers are recycled by the list, to display the items at the bottom of the list that have been scrolled into the viewport.  And perhaps the reason the items at the top of the list disappear is that they don't get their renderers back.  Just speculating.  But obviously this is undesirable behavior for the list.  Can anyone point me to a clear explanation of the lifecycle of cell renderers under different list events, such as list item deletions, scrolling into and out of view, etc?  This scenario seems too common to not have a workaround or programming idiom to handle it.

Any suggestions appreciated.

 

Regular Contributor
Posts: 86
Registered: ‎10-25-2010
My Device: Not Specified

Re: Cell Renderer Madness - Renaun if you see this please chime in

Are you deleting the data items out of the data Provider?

 

You can check out the filtering I do on data and then reset the list which should be a similar idea. Since deleting is basically filtering the data of the list's data provider.

 

Here is the example code:

http://renaun.com/blog/2011/02/playbook-sample-actionscript-application-using-qnx-components/

blog: http://renaun.com
twitter: @renaun
Developer
Posts: 1,251
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Cell Renderer Madness - Renaun if you see this please chime in

Yes, I'm deleting data items out of the list's dataprovider. I'm looking over your code example.  

 

BTW can you clarify which function call you mean when you say you reset the list?  Do you mean specifically and exclusively the setData method in ListContainer?  I notice you scroll to list items as well;  I found that scrolling a list will sometimes make previously invisible list items visible again, but not in every case.

 

In my case for example I have a list with 12 items, the last ~5 of which are not initially visible.  I then scroll to the end of the list, select the check boxes for the last 5 items (at this point the first ~5 items are not visible in the list viewport), and delete the last 5 items using the removeItemAt()  method of the list control.  This causes the list to no longer have more items than will fit in the viewport.  This is a case in which the first 4 list items disappear.  I had added some hackish code in my handler function that deletes checked list items, to scroll the list to the top and then back to the index of the last deleted item, and it works (i.e. gets the first few items in the list to re-render) as long as I don't delete too many items from the end of the list. 

 

My next hack was to loop through the dataprovider after deleting items, and using the methods of the list control,  get the indices of the list items that were not visible with getIsCellVisibleAtIndex(),  get the list items' objects using getItemAt(), and just put that object back into the same index with replaceItemAt(), but this did not get the items to render either.  This seems perhaps similar to but different from your setData() method, as you replace the entire dataProvider.  I'm guessing that replacing the entire dataProvider is the magic sauce here, that forces a brand new set of cell renderers to be instantiated, but it seems kind of brute force.  Again it would be great to find a good writeup on cell renderer lifecycle management but for now I'll settle for a hack that works reliably.

Developer
Posts: 1,251
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Cell Renderer Madness - Renaun if you see this please chime in

An update:  Completely replacing the list's dataProvider fixes this rendering problem.  I'm assuming here that the old dataProvider object that gets supplanted is supposed to lose all references and become eligible for garbage collection - Renaun can you confirm that is the way your code is supposed to work?

 

Thanks again.