我有一个从网址下载的图片列表(包含说明)。一切都很好,直到我将列表滚动到顶部。再次拍摄照片,因为(我猜)方法再次调用getView()。如何使图像只下载一次?在ArrayAdapter类下面
public class ImageWithTwoTextArrayAdapter extends
ArrayAdapter<ImageWithTwoText> {
public final static String TITLE_KEY = "title";
public final static String SUBTITLE_KEY = "subtitle";
public final static String IMAGE_RESOURCE_KEY = "imageResources";
private final List<ImageWithTwoText> imageWithTwoTextList;
private final Context context;
TextView titleView;
TextView subTitleView;
ImageView imageView;
/**
* Class constructor
*
* @param context
*/
public ImageWithTwoTextArrayAdapter(Context context,
List<ImageWithTwoText> imageWithTwoTextList) {
super(context, R.layout.row_view, imageWithTwoTextList);
this.context = context;
this.imageWithTwoTextList = imageWithTwoTextList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.row_view, parent, false);
ImageWithTwoText currentElement = imageWithTwoTextList.get(position);
titleView = (TextView) rowView.findViewById(R.id.title);
subTitleView = (TextView) rowView.findViewById(R.id.subtitle);
imageView = (ImageView) rowView.findViewById(R.id.icon);
titleView.setText(currentElement.getTitle());
subTitleView.setText(currentElement.getSubTitle());
if (currentElement.getImageResource() != null) {
imageView.setImageResource(currentElement.getImageResource());
} else {
if (imageView.getDrawable() == null) {
new DownloadThumbnailTask(imageView).execute(currentElement
.getImageURI());
}
}
return rowView;
}
}