I found two problems with ListView when I have a custom itemrender :
- Adding one row of data calls the onDataChanged(…) 5-7 times
Example:
var listView = new ListView();
listView.percentWidth = 100;
listView.percentHeight = 100;
listView.itemRenderer = new MyTestItemRender();
var gameRoomList = new ArrayDataSource<Dynamic>();
listView.dataSource = gameRoomList;
gameRoomList.add({ myName : "One", count : 3});
Screen.instance.addComponent(listView);
class MyTestItemRender extends ItemRenderer
{
public function new() {
super();
}
private override function onDataChanged(data:Dynamic)
{
super.onDataChanged(data);
if (data != null) {
trace("Call onDataChanged");
}
}
}
- Removing a row from the datasource ( with
listView.dataSource.removeAt(i)
) lead to wrong interpretation of the components in the next row wich replaced the removed one.
It’s a bit more complicated to give an example here because the bug from 1), but it goes something like this:
class MyTestItemRender extends ItemRenderer
{
var myHBox:HBox;
public function new() {
super();
myHBox = new HBox();
this.addComponent(myHBox );
}
private override function onDataChanged(data:Dynamic)
{
super.onDataChanged(data);
if (data != null) {
// check some criteria and add different count of image components
.......
var myImage:Image = new Image();
var myImage.....
var myImage....
.... //set image resource
myHBox.addComponent(myImage);
myHBox.addComponent(myImageTwo);
myHBox.addComponent(.....);
}
}
where I add three rows in the list view
gameRoomList.add({ myName : "One", count : 3});
gameRoomList.add({ myName : "Two", count : 4});
gameRoomList.add({ myName : "Three", count : 2});
Let’s say I have a button and when I click it I will call listView.dataSource.removeAt(2)
The second row will disapear , but it will keep the count of components of that missing row ( example 4 ) and not the correct one 2 ( from the third row)
It’s a little bit hard to exaplin it , but if you want I can try to create more comple example.