【发布时间】:2014-03-04 19:11:18
【问题描述】:
我有一个用于列表视图的自定义适配器。它有 3 个字段:一个缩略图和两个文本字段。
布局膨胀后,将从外部服务器下载缩略图。
如何更改功能,以便仅在用户向下滚动时下载图像。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Inflate the layout
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_single, parent, false);
ImageView image = (ImageView) rowView.findViewById(R.id.picture);
TextView firstline = (TextView) rowView.findViewById(R.id.firstline);
TextView secondline = (TextView) rowView.findViewById(R.id.secondline);
// Get information about the report
AnimalLocationLog current = objects.get(position);
// Get all the important information
String species = current.getSpecies();
String sanitizedSpecies = MiscHelpers.sanitizeString(species);
int reportId = objects.get(position).getTrackerId();
// Construct the URL to the image
String imageLocation = websiteUrl + sanitizedSpecies + separator + reportId + extension;
// Display user report
downloader.download(imageLocation, image);
firstline.setText(species);
secondline.setText("Spotted " + current.getDateTime().toString("yyyy-MM-dd H:m"));
return rowView;
}
【问题讨论】:
-
此代码看起来可以满足您的要求。
-
@AdamS 是对的 getView 仅在列表视图需要屏幕上的视图时调用。
-
谢谢@AdamS - 请发表答案,我会接受的