I am using array adapter to populate a list of places with custom data. The text loads correctly, the problem lies on the image loading. I am using the Universal-image-loader to load images asynchronously. The images are loaded but they are placed in the wrong order on the list and also they just keep reloading over and over again in the wrong place. Here is my adapter code:
public class PlacesListViewAdapter extends ArrayAdapter<PlacesListItem> {
private final Context context;
protected ImageLoader imageLoader = ImageLoader.getInstance();
public PlacesListViewAdapter(Context context, int resourceId, List<PlacesListItem> places) {
super(context, resourceId, places);
this.context = context;
}
private class ViewHolder {
ImageView ivPlaceLogo;
TextView txtPlaceName;
TextView txtPlaceType;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
PlacesListItem placesListItem = getItem(position);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.places_list_item, parent, false);
holder = new ViewHolder();
holder.txtPlaceName = (TextView) convertView.findViewById(R.id.place_name);
holder.txtPlaceType = (TextView) convertView.findViewById(R.id.place_type);
holder.ivPlaceLogo = (ImageView) convertView.findViewById(R.id.place_logo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtPlaceName.setText(placesListItem.getPlaceName());
holder.txtPlaceType.setText(placesListItem.getPlaceType());
imageLoader.displayImage(placesListItem.getPlaceLogoURL(), holder.ivPlaceLogo);
return convertView;
}
}
placesListItem?