I'm desperately trying to fix a strange behavior in my custom iconitemrenderer list: When I change the view to the view with the list inside and start scrolling, the list gets white for the fraction of a second (apperently completely redrawn), but only once when scrolling the first time after the view change.
In the IconItemRenderer I add a check mark:
<s:IconItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
...
override protected function commitProperties():void
{
//create checkbox
if(!checkMarkImage && data.isChecked) {
//create image holder
imageHolder = new Group;
addChild(imageHolder);
//create image
checkMarkImage = new BitmapImage();
checkMarkImage.source = checkBoxSource;
imageHolder.addElement(checkMarkImage);
}
//delete checkmark
else if(checkMarkImage && !data.isChecked) {
removeChild(imageHolder);
imageHolder = null;
checkMarkImage = null;
}
super.commitProperties();
}
override protected function layoutContents(w:Number, h:Number):void
{
super.layoutContents(w, h);
//layout the checkmark
if(checkMarkImage) {
// don't do it like this! (see correct answer)
checkMarkImage.x = w-40;
checkMarkImage.y = 14;
}
}
The list change handler sets the mark on the selected item and removes it from the old one. After this is done it calls popView(), but when you come again to this view the list gets created in the views addHandler and when you start scrolling the list behaves as mentioned above.
//list change
protected function myList_changeHandler(event:IndexChangeEvent):void
{
//is already selected?
var item:Object = myList.selectedItem;
if(!item.isChecked) {
//deselect the other one?
var length:int = myList.dataProvider.length;
var oldItem:Object;
for(var i:int = 0; i < length; i++) {
oldItem = myList.dataProvider.getItemAt(i);
if(oldItem.isChecked) {
oldItem.isChecked = false;
myList.dataProvider.itemUpdated(oldItem);
break;
}
}
//select new one
item.isChecked = true;
myList.dataProvider.itemUpdated(item);
}
//pop view
navigator.popView();
}
I think the problem is in the myList.dataProvider.itemUpdated(oldItem), apperently the renderer thinks it has to redraw everthing, but I have no idea why.. and why only after the view is shown again...?
Any ideas if it's a bug or something? how can I get rid of this bahavior or how can I debug this this properly? thanks