Android:ImageView.setImageResource在gridviewadapter中显示不正确

时间:2016-06-14 07:49:48

标签: android gridview getview

我定义了gridview和gridviewadapter来选择图像。选择2个或更多图像时,一切运行良好。但是,当我选择1时,位置= 1被positon = 0中的图像覆盖,这仅在第一次选择1图像时发生。流程是适配器中的getView():

"launch" : [ 
             { _id: '56cea954d82cd11004ee67b5',
               .... other fields
             },
             { _id: '56ceaa00d82cd11004ee67bc',
              .... other fields
             },
          ]

错误显示: enter image description here

正确显示: enter image description here

xml文件:

 @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        L.d("mytest position ="+position+ "converView ="+convertView);
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = mInflater.inflate(R.layout.grid_view_item, null);
            holder.mSelectImage = (NGImageView) convertView.findViewById(R.id.iv_icon);
            convertView.setTag(holder);
        } else {

            holder = (Holder) convertView.getTag();
        }
        if (getData().size() > 0 && position != getData().size()) {
            holder.mSelectImage.setVisibility(View.VISIBLE);
            ImageItem imageItem = getData().get(position);
            if (imageItem != null) {
                if (imageItem.getImageUri().toString().startsWith("http")) {
                    loadNGImageView.LoadOptionsView(imageItem.getImageUri().toString(),holder.mSelectImage);

                } else {
                    String imgUrl = BitmapUtil.IMAGE_URI_SUFFIX_SDCARD + imageItem.getImageUri().getPath();
                    L.d("mytest LoadOptionsView");
                    loadNGImageView.LoadOptionsView(imgUrl,holder.mSelectImage);
                }
            }
        } else {
            if (position == TopicPostFragment.DEFAULT_PHOTO_COUNT) {
                holder.mSelectImage.setVisibility(View.GONE);
            } else {
                holder.mSelectImage.setVisibility(View.VISIBLE);
                L.d("mytest setImageResource");
                holder.mSelectImage.setImageResource(R.drawable.guild_icon_img);
            }

        }

        return convertView;
    }

error logs:
mytest position =0  converView =null
mytest setImageResource

mytest position =0  converView =android.widget.FrameLayout{42cd7de8 V.E.....    
......I. 0,0-0,0 #7f0b0113 app:id/fl_item}
mytest setImageResource

                     ......

mytest position =0   converView =android.widget.FrameLayout{42eabc00 V.E..... 
........ 0,0-90,90 #7f0b0113 app:id/fl_item}
mytest LoadOptionsView

mytest position =1   converView =android.widget.FrameLayout{42cd7de8 V.E.....  
......I. 0,0-0,0 #7f0b0113 app:id/fl_item}
mytest setImageResource

1 个答案:

答案 0 :(得分:0)

setImageResource不能与setImageURL同时使用,有时setImageURL可能会覆盖setImageResource并使显示错误。 如果你同时使用它们,你应该先设置ImageURL(null),然后使用setImageResource。