Nifty refresh layout

Hello,

I just try to create a dynamic listview from an nifty listbox but when I relayout with layoutElements, I have a bug.
See below :

[video]http://www.youtube.com/watch?v=cFLm-HQ_l9c[/video]

Display method of my ListBoxViewConverter
[java]
@Override
public void display(Element item, TableRow row)
{
item.setConstraintHorizontalAlign(HorizontalAlign.center);
for (Element elmnt : row.getDatas())
{
elmnt.setConstraintWidth(SizeValue.wildcard());
elmnt.setConstraintHorizontalAlign(HorizontalAlign.center);

        item.add(elmnt);
    }
    item.getParent().layoutElements();
}[/java] 

For test, I add items directly from the bind method of the ListViewControl
[java]
TableRow row = new TableRow();
row.addData(new TextBuilder()
{{
style(“nifty-label”);
text(“data”);
}}.build(nifty, screen, element));

    row.addData(new TextBuilder()
    {{
        style("nifty-label");
        text("data2");
    }}.build(nifty, screen, element));
    addRow(row);
    
    TableRow _row = new TableRow();
    _row.addData(new TextBuilder()
    {{
        style("nifty-label");
        text("data3");
    }}.build(nifty, screen, element));
    
    _row.addData(new TextBuilder()
    {{
        style("nifty-label");
        text("data4");
    }}.build(nifty, screen, element));
    addRow(_row);
    
    TableRow _row2 = new TableRow();
    _row2.addData(new TextBuilder()
    {{
        style("nifty-label");
        text("data5");
    }}.build(nifty, screen, element));
    
    _row2.addData(new TextBuilder()
    {{
        style("nifty-label");
        text("data6");
    }}.build(nifty, screen, element));
    addRow(_row2);[/java] 

addRow(TableRow) is just a ListBox.addItem(TableRow)

And finnaly the xml controldef
Pastebin

I don’t see what is wrong but when I apply screen.layoutLayers() or item.getParent().layoutElements() there are a space added to all items line begining.

Additionnaly, when I display screen tree, I have : Parent : root (de.lessvoid.nifty.elements.Element@34175445) --> null (de.lessvoid.nifty.elements.Element@663dfcbc)

Thank for your help.

Solved !

When you relayout your listbox, the display method of the ViewConverter is recalled so it’s add the TableRow elements to the item line.
But at all relayout, elements are already added and make duplications, so you need to block this.

Just adding this line at first in the display method of the ViewConverter : [java]if(!item.getElements().isEmpty())
return;[/java]
Like this, if datas are already added, he don’t duplicate them;