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;
}