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
Developer
Posts: 116
Registered: ‎11-18-2010
My Device: BlackBerry PlayBook
My Carrier: null

List, call item renderer at.

Hi dear developers.

I have meet a problem with List again....

What I need is to call some method(s) at concrete item renderer in the List. Lets say row number 2 and 5 need to updated by calling some methods at their item renderer.

How can I do it?

 

Thanks a lot.

Yuriy.

Highlighted
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: List, call item renderer at.

If you're asking can you update the contents of a list that has a custom renderer, then yes.  You just need to update the data provider of the list.  The DataProvider class has various add and replace methods to add and update the contents which will automatically update your list.  If that is not what you're asking, please provide more information.

Developer
Posts: 116
Registered: ‎11-18-2010
My Device: BlackBerry PlayBook
My Carrier: null

Re: List, call item renderer at.

[ Edited ]

Hi and thanks for quick response.

 

Well, what I need is do not update data provider, but i need to update single item renderer (single row). What I do at AIR for desktop is:

 

 

var itemRenderer:IItemRenderer = this.contactList.dataGroup.getElementAt(i) as IItemRenderer;
itemRendererItem["showIncomingMessageAlert"]();
where i - is a row number and "showIncomingMessageAlert" is a public method that i can call to change some view exactly at this row.
Can I do same at qnx List?

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: List, call item renderer at.

The renderer defines the custom look for each item in the list.  The data provider contains the data needed for the renderer.  If you update/add to the data provider, the effected rows of the list will automatically update.  QNX does not have "item" renderers, just a single renderer for the entire list that each item in the list gets rendered based on the custom logic in the renderer.  You do not have to explicityly call a method of the renderer with the QNX List control.

 

Hope that helps, but I feel I am not seeing exactly what you are trying to do.

Developer
Posts: 165
Registered: ‎10-26-2010
My Device: BlackBerry® PlayBook™
My Carrier: .

Re: List, call item renderer at.

[ Edited ]

The only list event that specifically returns a reference to the cell is ListEvent.ITEM_CLICKED, and then, you access it via:

 

 

e.target.cell

 

 

... but as John says, you don't need to get a specific list item. Instead, in your CellRenderer class, you'd add logic  to catch an event (DATA_CHANGE is already built in and will cause the cell to re-render, so you could piggyback from it instead of adding another listener) and have that listener trigger the change you need instead of trying to call a method in the CellRenderer itself.

 

DATA_CHANGE automatically invokes the public set data method. This is also a good place to add any code that will depend on data to function since it will exist when this function fires. In the set data method, you'd add your logic along with changing any other data based on the new data to be set:

 

 

public function set data( object:Object ):void {

	data = object;

	if( data.newMessages > 0 ) {
		showIncomingMessageAlert();
	}
...

 

You'd use the same technique with your custom event if you decided to take it that far.

 

----------------------

 

Another note: If this thing you're showing isn't part of the CellRenderer itself, like a circle with a number in it beside the label would be part of the CellRenderer, but instead something that pops up like an alert, do NOT put it in the set data method. set data is also called every single time a list item becomes visible in the list. With something like an alert, every single time the list shows the item that has the "new messages" from my example will cause the alert, popup, whatever to show again.. and again... 

 

If it's something external, there has to be some better place to call this showIncomingMessagesAlert function... somewhere like the service where you're actually checking for these incoming messages.

 

 

Developer
Posts: 116
Registered: ‎11-18-2010
My Device: BlackBerry PlayBook
My Carrier: null

Re: List, call item renderer at.

[ Edited ]

Hello 

var i:uint;
var length:uint = this.list.dataProvider.length;
var item:AccountVO;
for (; i < length; ++i)
{
  item = this.list.dataProvider.getItemAt(i) as AccountVO;
  item.isEditMode = true;
  this.list.updateItemAt(item, 0);
  item = null;
}
I take appropriative row, modify it as I need and then - update it.
Here, i set a public var to true: item.isEditMode = true;
But with such way I can call public function also: item.showIncomingMessageAlert();
Sure, at cell renderer i process this at get data method.
Like this ...
I can't find other way to manage such task up to now.

 

Developer
Posts: 165
Registered: ‎10-26-2010
My Device: BlackBerry® PlayBook™
My Carrier: .

Re: List, call item renderer at.

[ Edited ]

Unless you use another array or a dictionary or some other extra data structure that contains the information you need, you can't tell which items in an array have a specific property without looping through and checking it.

 

If you only want the data items (not cellrenderer items) with EditMode set to true, then your application needs to keep references to and manage the references to the items have EditMode set to true in a separate data structure.

 

In other words, you'll have two arrays instead of one. One array will contain all of the data items and the other will contain references to the items in the main array that have EditMode set to true. Part of what's stored in the second array should be the index in the other array so you can use the second array to specifically call the items in the main list by index.

 

as an example:

 

 

Main Array:
{John, true}
{Sue, false}
{Jane, true}
{Edie, false}
{James, false}


Second Array: (you could also just store the index or keep a full reference to the entire item. the choice is yours.)
{John, 0}
{Jane, 2}

You'd loop through the second array, using the stored index to call specific items in the main array. You'd need to remember to add and remove items from this second array as required or you'll have a mess.

 

 

------------------------

 

As for showing the list of contacts which have sent new messages, if the incoming message alert is an item that is displayed on a cell renderer, then the cell renderer only needs to know when and how to draw that item based on the data, without your intervention. It doesn't need to have any special public function to call. The list takes care of updating the items as needed when data is changed. 

 

You also have to understand that even if your list has 40,000 items, you'll only ever have as many cell renderers as can be shown on the screen at one time, so you'll only ever be truly redrawing a 1 -20 items (which is nothing.. especially if it's just a label and this notifier thing) no matter how much data is updated.

 

Once a cell scrolls out of view, it is trashed and a new one is created at the top or bottom of the list, depending on scroll direction, if you want to think of it that way.

 

To see it in action, or a similar concept, go here:  http://www.arpitonline.com/blog/2009/08/02/optimized-list-a-pure-as3-list-with-renderer-recycling/

... and click theToggle Mask button, then scroll the list.