*i used ImageViewer in my app and i want to display images for user as
automatically change.*
*my code is *
String[] imageURLs = {
"
http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/300px-AGameOfThrones.jpg
",
"
http://awoiaf.westeros.org/images/thumb/3/39/AClashOfKings.jpg/300px-AClashOfKings.jpg
",
"
http://awoiaf.westeros.org/images/thumb/2/24/AStormOfSwords.jpg/300px-AStormOfSwords.jpg
",
"
http://awoiaf.westeros.org/images/thumb/a/a3/AFeastForCrows.jpg/300px-AFeastForCrows.jpg
",
"http://awoiaf.westeros.org/images/7/79/ADanceWithDragons.jpg"
};
ImageList imodel = new ImageList(imagess);
ImageViewer iv = new ImageViewer(imodel.getItemAt(0));
new UITimer(() -> {
if (i < 4) {
* ///... here i should change selected index, how i can do
this ?*
i++;
} else {
i = 0;
}
}).schedule(3000, true, hi);
class ImageList implements ListModel<Image> {
String[] images_str;
private int selection;
// public void setImages(String[] images_str) {
// this.images_str = images_str;
// }
private Image[] images;
private EventDispatcher listeners = new EventDispatcher();
public ImageList(String[] images_str) {
this.images_str = images_str;
this.images = new EncodedImage[images_str.length];
}
public Image getItemAt(final int index) {
if (images[index] == null) {
images[index] = placeholder;
Util.downloadUrlToStorageInBackground(images_str[index], "list" + index,
(e) -> {
try {
images[index] =
EncodedImage.create(Storage.getInstance().createInputStream("list" +
index)).scaledWidth(Display.getInstance().getDisplayWidth());
listeners.fireDataChangeEvent(index,
DataChangedListener.CHANGED);
} catch (IOException err) {
err.printStackTrace();
}
});
}
return images[index];
}
public int getSize() {
return images_str.length;
}
public int getSelectedIndex() {
return selection;
}
public void setSelectedIndex(int index) {
selection = index;
}
public void addDataChangedListener(DataChangedListener l) {
listeners.addListener(l);
}
public void removeDataChangedListener(DataChangedListener l) {
listeners.removeListener(l);
}
public void addSelectionListener(SelectionListener l) {
}
public void removeSelectionListener(SelectionListener l) {
}
public void addItem(Image item) {
}
public void removeItem(int index) {
}
};
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/6f762823-548b-4cbd-bc17-42b8e6e1a74d%40googlegroups.com.