Android Gridview随机重复项

时间:2014-02-02 12:39:29

标签: android gridview android-gridview

我正在使用GridView,并且在网格中复制视图存在问题,我从Facebook api获取图像,然后异步将图像加载到ImageView

更新 对于Asyncronus Image加载源,我来自Android教程中的BitmapFun

GalleryAdapter.java

private class ImageAdapter extends BaseAdapter{

        private final Context mContext;
        private List<String> mPhotos = new ArrayList<String>();

        public ImageAdapter(Context context){
            super();
            mContext = context;
        }

        public void setPhotos(String... url){
            mPhotos = Arrays.asList(url);
            notifyDataSetChanged();
        }

        public void setPhotos(List<String> url){
            mPhotos = url;
            notifyDataSetChanged();
        }

        @Override
        public int getCount() {
            return mPhotos.size();
        }

        @Override
        public String getItem(int position) {
            return mPhotos.get(position);
        }

        @Override
        public long getItemId(int position) {
            return getItem(position).hashCode();
        }

        @Override
        public int getViewTypeCount() {
            return getCount() + 1;
        }

        @Override
        public int getItemViewType(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView = (ImageView) convertView;
            if(imageView == null){
                imageView = new RecyclingImageView(mContext);
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setLayoutParams(new AbsListView.LayoutParams(150, 150));
            }

            mImageFetcher.loadImage(getItem(position), imageView);
            return imageView;
        }
    }

duplicated image duplicated image

更新 对于Asyncronus Image加载源,我来自Android教程中的BitmapFun

1 个答案:

答案 0 :(得分:0)

按照here所述尝试捕获位图。通过设置内存缓存将完成您的工作。

或者你可以Universal image loader这样做会抓住你。您只需将图像的网址传递给imageview

即可