Skip to content
Advertisement

Multiple SwipeableContainers in a single form

I want to create a list of SwipeableContainers in a boxlayout on codenameone.

list.add(createWidget("Banana")).
            add(createWidget("Apple")).
            add(createWidget("Juice"));

public SwipeableContainer createWidget(String info) {

    MultiButton button = new MultiButton(info);
    return new SwipeableContainer(FlowLayout.encloseCenterMiddle(deleteb),button);
    
}

Doing this returns an error “java.lang.IllegalArgumentException: Component is already contained in Container: Container[x=0 y=0 width=0 height=0 name=null, layout = FlowLayout, scrollableX = false, scrollableY = false, components = [MultiButton]].” This is the same syntax as used on the Codenameone tutorial provided at: https://www.codenameone.com/javadoc/com/codename1/ui/SwipeableContainer.html. However my code doesn’t seem to allow me to create multiple of these components.

Advertisement

Answer

I’m guessing the deleteb button is used by another button. If you modify this code as such it should work:

MultiButton button = new MultiButton(info);
Button deleteb = new Button(FontImage.MATERIAL_DELETE);
return new SwipeableContainer(FlowLayout.encloseCenterMiddle(deleteb),button);
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement