如何为下载列表视图的图片设置条件?

法哈
 public AvatarDownloader(Context context){
    //Make the background thread low priority. This way it will not affect the UI performance
    photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);

    //Find the dir to save cached images
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
        cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"/download/myApp/avatars/");
    else
        cacheDir=context.getCacheDir();
    if(!cacheDir.exists())
        cacheDir.mkdirs();

}

final int stub_id=R.drawable.ic_launcher;
public void DisplayImage(String url, String profilePic, Activity activity, ImageView imageView)
{
    if(cache.containsKey(url))
        imageView.setImageBitmap(cache.get(url));
    else
    {

        //queuePhoto(url, activity, imageView, profilePic);
        imageView.setImageResource(stub_id);
    }    
}

private void queuePhoto(String url, Activity activity, ImageView imageView, String profilePic)
{
    //This ImageView may be used for other images before. So there may be some old tasks in the queue. We need to discard them. 
    photosQueue.Clean(imageView);
    System.err.println("QPH"+url);
    PhotoToLoad p=new PhotoToLoad(url, imageView, profilePic);
    synchronized(photosQueue.photosToLoad){
        photosQueue.photosToLoad.push(p);
        photosQueue.photosToLoad.notifyAll();
    }

    //start thread if it's not started yet
    if(photoLoaderThread.getState()==Thread.State.NEW)
        photoLoaderThread.start();
}

在这里,我放置了代码图像下载器。如果服务器ic_launcher图片上显示的图片不可用,我想放置代码。如果图像可用,则显示在我的列表视图中。

维普尔·波罗希特(Vipul Purohit)

我建议使用Universal Image Loader进行图像加载/显示相关任务。它会自动处理内存管理,如果服务器上没有可用的映像,您可以设置自己的映像。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章