首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像在imageloader中复制

图像在imageloader中复制
EN

Stack Overflow用户
提问于 2013-06-13 17:38:12
回答 2查看 1K关注 0票数 1

我在getView()中使用imageloader,如下所示。但当picturepath为空时,我无法将ic_launcher作为默认图像。我不知道出了什么问题。但当我调试时,我发现当picturepath为空时,它会转到其他部分。但是仍然以某种方式加载了已存在的imagepath图像。这也只发生在列表的第一行。有人能帮我解决这个问题吗?

代码语言:javascript
复制
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);       
        }
EN

回答 2

Stack Overflow用户

发布于 2015-01-05 11:21:50

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

代码语言:javascript
复制
    options = new DisplayImageOptions.Builder()
            .resetViewBeforeLoading()
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .considerExifParams(true)
            .delayBeforeLoading(1000)
            .displayer(new SimpleBitmapDisplayer())
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();
票数 2
EN

Stack Overflow用户

发布于 2013-06-19 21:30:58

我认为你不需要设置if else语句。将您的"DisplayImageOptions“设置如下

代码语言:javascript
复制
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:“+名称);

将这段代码放入

代码语言:javascript
复制
ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.displayImage(image_poster_url, vh.imageView, options);

如果url为空或空url,则会自动显示ic_launcher。如果静止图像被复制,则在.build()之前将此块添加到DisplayImageOptions;

代码语言:javascript
复制
.resetViewBeforeLoading()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17083838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档