0

我正在尝试在 ListView 中显示提要消息。如果我在初始化 ListView 之前拥有所有可用的内容,那么它工作得很好。现在我正在尝试获取图像,因为图像很昂贵,我正在尝试进行延迟加载。我创建了一个获取对象的异步 http 函数。

据我了解,给定 ListView 的所有单元格都是在 ArrayAdapter 对象的单个实例中创建的。现在的问题是,当 async-http 函数返回数据时,对实际 ImageView 的引用已经被另一个单元格的另一个实例替换。结果,图像开始随机出现在每个地方。

我认为这是一个设计缺陷,我正在尝试这样做。

关于如何解决这个问题有什么更好的建议吗?(虽然仍然能够使用 async-http 调用进行延迟加载)

谢谢!

编辑:我用 ListView 和 ExpandableListView 试过这个,这是来自 ExpandableListView 实现的代码。

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.activity_feed_exlist_child_row, null);
        }

        String msgId        = data.get(childPosition).get("msgid");
        String picId        = data.get(childPosition).get("fileName");
        TextView txtMsg     = (TextView) convertView.findViewById(R.id.txtMsg);

        txtMsg.setText(data.get(childPosition).get("msg"));
        ImageView imgStatusMsgBackgroud = (ImageView) convertView.findViewById(R.id.imgStatusMsgBackground);

        String requestURL       = "picture.php?action=getPicture&picid=" + picId;
        MyHTTPRequest httpReq   = new MyHTTPRequest(requestURL, this);
        httpReq.startAsynchronous();

    return convertView;
}
4

1 回答 1

0

经过一番搜索,找到了一些很好的参考资料。谢谢大家。-使用 AsyncTask 在 ListView 中加载图像 - http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html

于 2012-08-19T04:46:58.473 回答