gpt4 book ai didi

java - 重新图像查看器问题

转载 作者:太空宇宙 更新时间:2023-11-04 13:03:37 25 4
gpt4 key购买 nike

来自 json 的图像按预期显示在 GridView 中,但是当我单击它们时,只能通过图像查看器滑动 2 个图像。我不需要像照片共享演示中那样上传图像,我只需在 GridView 中显示所有图像,然后单击时在图像查看器中显示它们。我很难做到这一点。以下是我到目前为止所做的事情。

图库表单

@Override
protected void beforeImgGallery(Form f) {
int iter = 0;
GridLayout gr = new GridLayout(1, 2);
Container grid = new Container(gr);
GridLayout gr = new GridLayout(1, 2);
grid.setScrollableY(true);
grid.addComponent(new InfiniteProgress());
f.addComponent(grid);
createPictureCommand(grid);
}

connectionRequest - 这里我不需要更新服务器中的图像:

private static boolean animating;
private Vector<Map<String, Object>> responsesgallery;
String[] galleryPhotoUrlCopy = new String[100];
int galleryIndex;

private void createPictureCommand(final Container grid) {
ConnectionRequest mp = new ConnectionRequest() {
private long key;

@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
results = p.parse(new InputStreamReader(input));
responsesgallery = (Vector<Map<String, Object>>) results.get("data");
for (int i = 0; i < responsesgallery.size(); i++) {
Hashtable hm = (Hashtable) responsesgallery.get(i);
String galleryImgId = (String) hm.get("news_id");

String galleryPhotoUrl = (String) hm.get("photo");
galleryPhotoUrlCopy[i] = galleryPhotoUrl;
galleryIndex = i;
key = (long) i;
long[] img = {key};
//problem lies in here
imageList = new ImageList(img);

final Button btn = createImageButton(key, grid, i, galleryPhotoUrl);
imageList.addImageId(key);
grid.addComponent(i, btn);
}
}

@Override
protected void postResponse() {
}
};
mp.setUrl(SERVER_URL);
NetworkManager.getInstance().addToQueueAndWait(mp);
}

Command createBackCommand(final Container viewerParent, final Container grid) {
return new Command("Back") {
@Override
public void actionPerformed(ActionEvent evt) {
viewerParent.getParent().replace(viewerParent, grid, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 300));
Form frm = Display.getInstance().getCurrent();
frm.removeAllCommands();
frm.setBackCommand(null);
}
};
}

图像列表类

public static final String SERVER_URL = "http://capitaleyedevelopment.com/~admin/traffic/api/news/getLatestNews";
private static String THUMB_URL_PREFIX = SERVER_URL + "image?";

class ImageList implements ListModel<Image> {

private int selection;
private long[] imageIds;
private EncodedImage[] images;
private EventDispatcher listeners = new EventDispatcher();

public void addImageId(long id) {
long[] n = new long[imageIds.length + 1];
EncodedImage[] nImages = new EncodedImage[n.length];
System.arraycopy(imageIds, 0, n, 0, imageIds.length);
System.arraycopy(images, 0, nImages, 0, images.length);
n[imageIds.length] = id;
imageIds = n;
images = nImages;
listeners.fireDataChangeEvent(-1, DataChangedListener.ADDED);
}

public long getSelectedImageId() {
return imageIds[selection];
}

public ImageList(long[] images) {
this.imageIds = images;
this.images = new EncodedImage[images.length];
}

public Image getItemAt(int index) {
System.out.println("index " + index);
System.out.println("images[index] " + images[index]);
if (images[index] == null) {
images[index] = placeholder;
Util.downloadUrlToStorageInBackground(galleryPhotoUrlCopy[index], "FullImage_" + imageIds[index], new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
images[index] = EncodedImage.create(Storage.getInstance().createInputStream("FullImage_" + imageIds[index]));
listeners.fireDataChangeEvent(index, DataChangedListener.CHANGED);
System.out.println("bibek check in ");
} catch (IOException err) {
err.printStackTrace();
}
}
});
}
// index = 3;
return images[index];
}

public int getSize() {
return imageIds.length;
}

public int getSelectedIndex() {
return selection;
}

public void setSelectedIndex(int index) {
WebServiceProxy.getPhotoLikesAsync(imageIds[selection], new Callback<Integer>() {
public void onSucess(Integer value) {
if (likeCount != null) {
}
}

public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
}
});
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) {
}
}

最佳答案

在模型的 getSize 方法中放置一个断点,然后查看返回的数组的长度。我假设它是 2 这可以解释你所看到的。

如果您不需要图像 ID 机制,只需将其替换为其他内容,并将模型映射到您的“真实”数据结构,这就是拥有模型的全部意义。

关于java - 重新图像查看器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34702116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com