0

I'm trying to show feed message in a ListView. It is working pretty good if I have all the content available before I initialize the ListView. Now I'm trying to fetch Images, since the Images are expensive I'm trying to do lazy loading. I have created an asynchronous http function that fetches the object.

From what I understand, all the cells for a given ListView are created within the single instance of ArrayAdapter object. Now the issue is, by the time async-http function returns with data the reference to the actual ImageView is already replaced by another instance of a different cell. As a result the image starts showing up randomly every where.

I think this is a design flaw, the way I'm trying to do it.

Any better suggestion, on how I can solve this issue ? (while still able to do the lazy loading with async-http calls)

Thank you!

Edit: I tried this with ListView and also with ExpandableListView, here is a code from the ExpandableListView implementation.

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;
}
Daniele
  • 1,005
  • 9
  • 26
bneupaane
  • 537
  • 1
  • 7
  • 16
  • pls post screenshots & for image loading you can use universal image loader library – rajpara Aug 19 '12 at 03:17
  • 1
    After some more searching, found some good references. Thanks all. - http://stackoverflow.com/questions/7729133/using-asynctask-to-load-images-in-listview - http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html – bneupaane Aug 19 '12 at 04:16

1 Answers1

0

After some more searching, found some good references. Thanks all. - Using AsyncTask to load Images in ListView - http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html

Community
  • 1
  • 1
bneupaane
  • 537
  • 1
  • 7
  • 16