Android 在ListView适配器中加载位图/图像

Android 在ListView适配器中加载位图/图像,android,android-listview,android-asynctask,android-adapter,android-bitmap,Android,Android Listview,Android Asynctask,Android Adapter,Android Bitmap,我正在尝试在具有ArrayAdapter的ListView中添加图像。仅供参考,toList()是从迭代器到给定DBObject列表的转换 我覆盖了视图getView(),并设置了文本视图和图像 private static class EventAdapter extends ArrayAdapter<DBObject> { public EventAdapter(Context context, int resource, Iterable<DBObj

我正在尝试在具有ArrayAdapter的ListView中添加图像。仅供参考,toList()是从迭代器到给定DBObject列表的转换

我覆盖了
视图getView()
,并设置了文本视图和图像

private static class EventAdapter extends ArrayAdapter<DBObject> {      

    public EventAdapter(Context context, int resource, Iterable<DBObject> events) {
        super(context, resource, toList(events));           
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        View v = convertView;               
        LayoutInflater vi = LayoutInflater.from(getContext());                              
        v = vi.inflate(R.layout.adapter_event_list, null);

        DBObject event = getItem(position);

        if (event != null) {

            //Get the logo if any
            if( ((DBObject)event.get("events")).containsField("logo") ){      

                String logoURL = ((DBObject)((DBObject)event.get("events")).get("logo")).get("0").toString();
                ImageView eventLogo = (ImageView) v.findViewById(R.id.eventLogoList);
                new setLogo().execute(logoURL, eventLogo);

            }               
            TextView title= (TextView) v.findViewById(R.id.eventTitleList);             
            title.setText( ((DBObject)event.get("events")).get("title").toString() );               

        }

        return v;
    }

    protected static <T> List<T> toList( Iterable<T> objects ) {
        final ArrayList<T> list = new ArrayList<T>();
        for( T t : objects ) list.add(t);
        return list;
    }
    //setLogo() method here. See below
 }
我这样做了(使用异步),我认为这是从URL加载图像的正确方法。我看到了这一点,并从中借用了
downloadbimat()
方法

如上所述,图像加载到ListView的错误位置。加载它们的可靠方法是什么

另外,在AsyncTask中传递
v.findViewById(R.id.eventLogoList)
的想法是,程序将区分每个适配器的ImageView,但似乎没有


更新

在跟踪导致这种混合的问题后,我发现

我更改了代码,以检查
是否是问题的根源

//Get the logo if any               
if( ((DBObject)event.get("events")).containsField("logo") ){                        
        String logoURL = ((DBObject)((DBObject)event.get("events")).get("logo")).get("0").toString();
        ImageView eventLogo = (ImageView) row.findViewById(R.id.eventLogoList);

        //new setLogo().execute(logoURL, eventLogo);   

        TextView title= (TextView) row.findViewById(R.id.eventTitleList);
        title.setText( "Shit happens" );    

    }
假设我有40件物品。
logo
字段存在的字段上设置了
logo
。如果我向下/向上滚动,顺序会改变,文本会变得混乱。这是因为在循环中创建的堆栈小于列表的最大值..我猜。。。我还在挣扎

PS:我发现可以异步加载图像,而不是DYI


更新2


我添加了一个带有静态url的else。由于加载图像所需的时间,它们仍然放错了位置。

我真的会选择像毕加索这样的好图书馆。 它将为你处理所有困难的部分,而且写得很好。

谢谢你的图书馆,我试过了,但是内容仍然混乱。
//Get the logo if any               
if( ((DBObject)event.get("events")).containsField("logo") ){                        
        String logoURL = ((DBObject)((DBObject)event.get("events")).get("logo")).get("0").toString();
        ImageView eventLogo = (ImageView) row.findViewById(R.id.eventLogoList);

        //new setLogo().execute(logoURL, eventLogo);   

        TextView title= (TextView) row.findViewById(R.id.eventTitleList);
        title.setText( "Shit happens" );    

    }