Skip to content
Advertisement

codename one container with action listener

I am developing my first mobile App with Codename One. I am trying to get a container to react to an normal click action event. I have a container (note this is not a swing container, but a codename one container), which contains list elements in a box Y_axis layout that is scrollable. so far so good. these elements are containers themselves, which house labels, an image and a star slider.

now, when the user clicks anywhere in the whole element container, I want to switch to another form to show the details of that entry. however, container does not offer to add an action listener. just implementing the actionlistener interface does not help either. Next problem is, the codename one container does not have a mouselistener either, as mobile apps do not have mouses to click.

so, how can I recognize clicking on a container?

Thanks and best regards

Advertisement

Answer

Create a button and give it your actionListener, then set it as the container’s leadComponent and the good thing is you don’t have to add it to the container.

Button myBtn = new Button();
myBtn.addActionListener(e -> {
    //go to other form here
});

Container myCont = new Container();
myCont.setLeadComponent(myBtn);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement