我在getView()中使用imageloader,如下所示。但当picturepath为空时,我无法将ic_launcher作为默认图像。我不知道出了什么问题。但当我调试时,我发现当picturepath为空时,它会转到其他部分。但是仍然以某种方式加载了已存在的imagepath图像。这也只发生在列表的第一行。有人能帮我解决这个问题吗?
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);
}发布于 2015-01-05 11:21:50
您应该尝试使用DisplayImageOptions的.resetViewBeforeLoading()。
options = new DisplayImageOptions.Builder()
.resetViewBeforeLoading()
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.delayBeforeLoading(1000)
.displayer(new SimpleBitmapDisplayer())
.bitmapConfig(Bitmap.Config.RGB_565)
.build();发布于 2013-06-19 21:30:58
我认为你不需要设置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为空或空url,则会自动显示ic_launcher。如果静止图像被复制,则在.build()之前将此块添加到DisplayImageOptions;
.resetViewBeforeLoading()https://stackoverflow.com/questions/17083838
复制相似问题