replace container in table layout

26 views
Skip to first unread message

Maaike

unread,
Dec 8, 2014, 4:39:45 PM12/8/14
to codenameone...@googlegroups.com
Hello,

I'm trying to replace a container in a table layout:

Container newContainer = getNewContainer();
tableContainer.replace(oldContainer, newContainer, null);
activityContainer.revalidate();

The old container is indeed gone. However, the new container is placed on the bottom of the Container with the TableLayout, instead of replacing the old one.

With the following code, the same happens (maybe replace is doing the same):

int oldContainerIndex = tableContainer.getComponentIndex(oldContainer);
tableContainer.remove(oldContainer);
tableContainer.addComponent(newContainer, oldContainerIndex);

Is this supposed to work (so somewhere my code is wrong) or is there another way to replace a container in a TableLayout?

Maaike

unread,
Dec 8, 2014, 4:44:37 PM12/8/14
to codenameone...@googlegroups.com
Of course I'm using removeComponent instead of remove().

Shai Almog

unread,
Dec 9, 2014, 1:33:51 AM12/9/14
to codenameone...@googlegroups.com
Replace is a bit tricky in a table layout because of all the cross dependencies and the behavior of the constraint class. As a workaround I would suggest wrapping the specific container in another container with border layout (place the internal in the center) then replace as usual. That way the table layout stays exactly the same and only the content of the cell is updated.
Reply all
Reply to author
Forward
0 new messages