我有一个画布,我在中心显示一张图像。此图像通过url下载。实际上还有更多的图片要下载,这意味着如果用户点击右键,我必须显示下一个图像,如果左,我必须显示另一个图像从背面。我有存储url图像的字符串数组。我想在后台下载上一张和下一张图片。如何做到这一点?
发布于 2011-12-09 02:10:48
以下是您需要考虑的一些问题,以使此要求在一系列设备上工作
JavaME ?
这个名单还在继续……
interface NetworkIoItem {
Object sourceComponent;
public void onImageDownload(Image image) {
//Trigger the source
}
}。
class NetworkIoManager extends Threads {
Vector pendingRequestQueue;
:
:
public void run() {
//Wait on the pending request queue
//Process all the elements in pending request queue
//and again wait on this queue
}
}。
class CacheManager {
Vector cachedContent;
public boolean checkIfCached() {
//Check in the cachedContent whether
//this image exists if so return true;
}
public Image fetchImage() {
//Check if the image is cached
//if so return this cached image
//else push a NetworkIoItem object to
//NetworkIOManager pending queue
}
}现在,对于调用CacheManager.fetchImage()的每个图像(当前、左侧或右侧),此方法将负责为您提供缓存或从服务器下载的图像。在相同的方法中,如果图像没有被缓存,它会将NetworkIoItem对象添加到NetworkIoManager pendingQueue并下载它。下载完成后,将触发NetworkIoItem.onImageDownload(...)方法。
您可以在NetworkIoManager中使用J2ME Polish's Touch功能下载镜像
通过使用这种方法,您将对请求URL进行异步图像获取。
发布于 2011-12-09 01:43:43
做一些像这样的事情..
Thread t = new Thread(new Runnable(){
public void run() {
// Your code to download image here as you were doing earlier,
// for previous and next image
}
});
t.start();https://stackoverflow.com/questions/8432324
复制相似问题