Codenameone刷新图像列表,而无需重新加载页面

Codenameone刷新图像列表,而无需重新加载页面

问题描述:

我正在开发一个有要求的应用程序,我们需要创建一个动态的图片库,该图片库会在几分钟后刷新。当刷新发生时,应该发生三件事而无需重新加载页面

I am Working on an app with requirement where we need to create a dynamic image gallery which refreshes after few minutes.When refresh happens three things should happen without reloading the page

1)应删除过时的图像
2)应添加新图像
3)非过时的图像应保留(不重新加载)
4)图像应以彼此相邻的方式堆叠它将主要用于平板电脑上。

1) Obsolete images should be removed 2) New Images should be added 3) Non Obsolete images should stay (not reload) 4) Images should be stacked next to each other as it will be mostly used on tablet

我正在查看Boxlayout或FlowLayout,可以添加图像,但不确定如何动态删除它。我能够为图像组件设置UUID,但无法根据UUID删除它。如何根据添加到表单中的UUID获取组件?
这是正确的方法吗?

I was looking at Boxlayout or FlowLayout and I can add the image but I am not sure how to delete it dynamically .I was able to set UUID for the image component but was not able to get component based on UUID to remove it . How can I get component based on its UUID added to the form ? Is this the correct approach ? or there is already build in component that does that .

我看到了这个

如何在使用UI构建器创建的渲染器中添加动态数据?

But I also read using List is discouraged 

https://www.codenameone.com/javadoc/com/codename1/ui/list/package-summary.html


使用 BoxLayout.Y_AXIS 容器实际上非常简单。创建图像组件以添加到框布局时,请执行以下操作:

This is actually pretty simple to do with a BoxLayout.Y_AXIS Container. When you create an image component to add to the box layout do this:

myImageComponent.putClientProperty("imageId", imageId);

然后,当您有回调刷新列表时,只需执行以下操作:

Then when you have the callback to refresh the list just do something like this:

for(Component cmp : parentContainer) {
    String id = (String)myImageComponent.getClientProperty("imageId");
    if(!existsInNewList(id)) {
       cmp.remove();
    }
}

完成容器更新后,只需调用 animateLayout(200) revalidate()刷新UI。

When you are done updating the container just call animateLayout(200) or revalidate() to refresh the UI.