Android ListView在viewholder中加载位图会引发memoryException

Android ListView在viewholder中加载位图会引发memoryException,android,listview,xamarin,Android,Listview,Xamarin,我正在将图像加载到一个viewholder中,该viewholder在listview中用于重用行的布局。但是在刷新列表几次之后,我得到了一个内存异常。此外,我加载位图的大小是imageloader类所需的,它以前一直工作正常,所以这不是问题所在 适配器的GetView方法: public override View GetView (int position, View convertView, ViewGroup parent) { BaseBundelVO bund

我正在将图像加载到一个viewholder中,该viewholder在listview中用于重用行的布局。但是在刷新列表几次之后,我得到了一个内存异常。此外,我加载位图的大小是imageloader类所需的,它以前一直工作正常,所以这不是问题所在

适配器的GetView方法:

public override View GetView (int position, View convertView, ViewGroup parent)
    {
        BaseBundelVO bundle = _bundles [position];
        string cellType = getCellType (bundle.Type);

        DSBundleListItem holder=null;
        View view = convertView;  


        if (convertView == null) 
        {
            if (cellType == "dsBundleCell") 
            {
                holder = new DSBundleListItem (_activity);
                view = _activity.LayoutInflater.Inflate (Resource.Layout.dsBundleListItem, null);
                holder.IconIv = view.FindViewById<ImageView> (Resource.Id.iconIv);
                holder.CoverIv = view.FindViewById<ImageView> (Resource.Id.coverIv);
                holder.BundleProgress = view.FindViewById<ProgressBar> (Resource.Id.bundleProgress);

                view.Tag = holder;
            }
        }
        else
        {
            if (cellType == "dsBundleCell") 
            {
                holder = view.Tag as DSBundleListItem;
            }
        }

        holder.LoadImage (bundle.CoverImageLocation,bundle.Icon);

        return view;
    }
public void SetData(List<BaseBundelVO> bundles)
    {
        _bundles = bundles;
    }
刷新适配器:

public override View GetView (int position, View convertView, ViewGroup parent)
    {
        BaseBundelVO bundle = _bundles [position];
        string cellType = getCellType (bundle.Type);

        DSBundleListItem holder=null;
        View view = convertView;  


        if (convertView == null) 
        {
            if (cellType == "dsBundleCell") 
            {
                holder = new DSBundleListItem (_activity);
                view = _activity.LayoutInflater.Inflate (Resource.Layout.dsBundleListItem, null);
                holder.IconIv = view.FindViewById<ImageView> (Resource.Id.iconIv);
                holder.CoverIv = view.FindViewById<ImageView> (Resource.Id.coverIv);
                holder.BundleProgress = view.FindViewById<ProgressBar> (Resource.Id.bundleProgress);

                view.Tag = holder;
            }
        }
        else
        {
            if (cellType == "dsBundleCell") 
            {
                holder = view.Tag as DSBundleListItem;
            }
        }

        holder.LoadImage (bundle.CoverImageLocation,bundle.Icon);

        return view;
    }
public void SetData(List<BaseBundelVO> bundles)
    {
        _bundles = bundles;
    }
包含listview的片段中的处理程序:

void AllBundelsLoadedHandler (List<BaseBundelVO> bundels)
{
    list.OnRefreshCompleted ();
    adapter.SetData (bundels);
    adapter.NotifyDataSetChanged ();
}

你能告诉我你在哪里使用这个适配器吗?可能您正在多次创建it适配器,而不仅仅是刷新列表。我已经更新了帖子:)如果您这样发布
代码片段,我们将无法为您提供帮助。我的意思是显示你的
活动/片段
你在哪里初始化/使用
适配器
。否则,如我所说,检查您是否在该
片段/活动中多次创建它,而不是仅仅刷新它。我不会多次创建它。我建议您使用业界领先的库来完成此类任务,如Glide(由谷歌推荐)、毕加索、Fresco或UIL。举个例子,如果滑翔机会因为同样的问题而坠毁,那就试试滑翔机。这样,您就可以确定这是您的ImageLoader问题还是ViewHolder之类的其他问题。