02-03-2011 06:14 PM
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?
Solved! Go to Solution.
02-03-2011 06:39 PM
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!
02-03-2011 07:00 PM
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
02-03-2011 07:05 PM
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" ![]()