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
Contributor
cyangreen
Posts: 10
Registered: ‎01-25-2011
My Device: Not Specified
Accepted Solution

TileList not preserving order of data with custom CellRenderer

HI all,

 

I was hoping you guys could help me with this, I've done a search and nobody seems to be experiencing the same problem.  So first the setup: I have a TileList set up with one row in it.  This TileList is using a custom class that extends CellRenderer to display its data. The problem is that if I scroll so the first element isn't visible anymore, its value is replaced by another element in my dataProvider.

 

Here's my code for the CellRenderer (where I'm assuming the problem lies):

 

 

	public class MyRenderer extends CellRenderer
	{
		private var renderer:MyDataDisplay = new MyDataDisplay();
		public function MyRenderer()
		{
			super();
		}
		
		override protected function onAdded():void{
			super.onAdded();
			addChild(renderer);
		}
		
		override protected function onRemoved():void{
			super.onRemoved();
			removeChild(renderer);
		}
		
		override protected function drawLabel():void{
			super.drawLabel();
			if(data){
				renderer.title.text= data.name as String;
				renderer.date.text = data.date as String;
			}
		}

 Help?

 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: TileList not preserving order of data with custom CellRenderer

hey cyangreen,

 

cell renderers and lists are the achilie heels of the QNX API's when it comes to figuring them out haha. and once you think u got it down, something unexpected happens and you have to change it up again lol.

 

i've run into problems here and there and usually when setting the data and what not, i override the public data() setter. that way i get accurate results. the cell renderer and list do some funky things sometiems and get weird read outs. so try doing that and see if that changes anything. so instead of overriding the drawLabel() method, override the data() setter:

 

 

override public function set data(data:Object):void
{
	super.data = data;
	
	if (data.name && data.data)
	{
		renderer.title.text= data.name as String;
		renderer.date.text = data.date as String;
	}
}

 

lemme know how that turns out. if it doesnt work, we'll try something else. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
Contributor
cyangreen
Posts: 10
Registered: ‎01-25-2011
My Device: Not Specified

Re: TileList not preserving order of data with custom CellRenderer

Thanks so much JRab, that did it.

 

For anyone experiencing similar issues, you have to remember to override onAdded and onRemoved:

 

override protected function onAdded():void{
			super.onAdded();
			addChild(el); //for all visual elements you want to add to this renderer
}
		
		override protected function onRemoved():void{
			super.onRemoved();
			removeChild(element); //do this for all visual elements you've added
		}

 

 

If you don't do this, your data will start overlapping itself and start acting really wonky. 

 

Thanks again JRab

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: TileList not preserving order of data with custom CellRenderer

not a problem at all. just glad you got it figured out and thanks for the tip!

 

p.s i like your choice of wording: "wonky" :smileyvery-happy:

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.