codenameone

How do I click a button contained in a InfiniteContainer by programming?


I have a form with an InfiniteContainer(bodyCnt) which contains 3 containers.

All of the 3 containers have their client properties.

I search for a container in bodyCnt with client property = 'search_tag' by programming.

            while (n<20){
            ((InfiniteContainer)cnt).continueFetching();
            for (int i=0; i<cnt.getComponentCount();i++){
                if (cnt.getComponentAt(i).getClientProperty(tag)!=null){
                    if (cnt.getComponentAt(i).getClientProperty(tag).equals(search_tag)){
                        cmp = cnt.getComponentAt(i);
                    }
                }
            }
            n++;
        }

The last container shows two times in the InfiniteContainer. Please refer to the screenshot below for the duplicate containers marked with a red square.

enter image description here


Solution

  • InfiniteContainer is asynchronous and blank at this point. Notice that the one component you see in it is a special case marker component we use to fill up the container when you reach the edge.

    Since you never saw the InfiniteContainer the marker component won't fetch components and the container will remain effectively empty.

    You can trigger a fetch by invoking: continueFetching() on the InfiniteContainer but you would have no standard event to indicate the initial set of components has arrived since it runs in the background.

    However, since you implement the fetch callback you can provide your own asynchronous event when the first fetch completed and use that as a hook for your logic.