Android 图像在imageloader中被复制

Android 图像在imageloader中被复制,android,imageview,universal-image-loader,Android,Imageview,Universal Image Loader,我在getView()中使用imageloader,如下所示。但是当picturepath为空时,我无法将ic_启动器作为默认图像。我不知道出了什么问题。但当我调试时,我发现当picturepath为空时,它会自动转到其他部分。但无论如何,现有的imagepaths图像还是被加载了。这种情况也只发生在列表的第一行。有人能帮我解决这个问题吗 public View getView(int position, View convertView, ViewGroup parent) {

我在
getView()
中使用
imageloader
,如下所示。但是当
picturepath
为空时,我无法将
ic_启动器
作为默认图像。我不知道出了什么问题。但当我调试时,我发现当picturepath为空时,它会自动转到其他部分。但无论如何,现有的imagepaths图像还是被加载了。这种情况也只发生在列表的第一行。有人能帮我解决这个问题吗

public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder vh = null;
            if (convertView == null)
            {
                convertView = View.inflate(context, layoutResourceId, null);
                vh = new ViewHolder();
                vh.nameTextView = (TextView) convertView.findViewById(R.id.name);

                vh.imageView = (ImageView) convertView.findViewById(R.id.list_image);

                convertView.setTag(vh);
            }else{
                vh = (ViewHolder)convertView.getTag();
            }

            String picturePath = detailsUrl.get(position);

            vh.nameTextView.setText("Name: "+name);
            if(picturePath !=null && !picturePath.equals(""))
            {
            imageLoader.displayImage("file://"+picturePath , vh.imageView);
            }
            else
            {
                     // I am able to see here the control flows when the imagepath is empty
                vh.imageView.setImageResource(R.drawable.ic_launcher);  
            }


        return (row);       
        }

我认为您不需要设置if-else语句。 设置“DisplayImageOptions”,如下所示

DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showStubImage(R.drawable.ic_launcher)
            .showImageForEmptyUri(R.drawable.ic_launcher)
            .showImageOnFail(R.drawable.ic_launcher)
            .bitmapConfig(Bitmap.Config.RGB_565) //and other options you may need
            .build();
那么在这个声明之后,

vh.nameTextView.setText(“名称:”+Name)

把这段代码

ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.displayImage(image_poster_url, vh.imageView, options);
如果url为null或空url,则会自动显示ic_启动器。 如果静态图像被复制,请在.build()之前将此块添加到DisplayImageOptions


您应该使用DisplayImageOptions尝试.resetViewBeforeLoading()

    options = new DisplayImageOptions.Builder()
            .resetViewBeforeLoading()
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .considerExifParams(true)
            .delayBeforeLoading(1000)
            .displayer(new SimpleBitmapDisplayer())
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();

+谢谢你的回复。我已经试过了。这解决了重复问题,但在logcat中显示IO异常。当然,它不会给力带来接近。但我还是想避免这个错误。你能推荐一下吗?
    options = new DisplayImageOptions.Builder()
            .resetViewBeforeLoading()
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .considerExifParams(true)
            .delayBeforeLoading(1000)
            .displayer(new SimpleBitmapDisplayer())
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();