Frage

I have four buttons at the bottom of my form. Clicking on any of these buttons results into a container preparation. In this container I've five components(includes buttons) and this container can be in three states(changes on button click which is inside the container).

By three states I mean every time I press a button which is added to this container as a component I need to replace a few/ add one or two components and then display the container again.

Now, here I'm confused whether should I go for the replacement of the components which are there inside the container or should I create a new container on every button click and swap the whole container itself.

PS:more concerned about the performance.

regards.

War es hilfreich?

Lösung

You can add and remove element from the container with addComponent() and removeComponent(). Is is quite similar to an vector of elements.

I wrote about an example for Codename One, where I swap components in a grid: http://meier-online.com/en/2012/10/codename-one-mirror-grid/ This should work the same in lwuit (except perhaps the animation)

I don't think there is much performance difference between changing containers or changing components inside them. For repaint, the layout must be recalculated in both cases, and the container itself has not such a big memory footprint (like for example an image). But you should notice that a Component has a method getParent(), so it is meant to have only one parent. So I would use only one container and swap the elements.

Andere Tipps

You can swap the components using a Container method called replace, where you only need to pass the new Component and the old one. You can use an animation too or set it to null.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top