我实现了一个无休止的滚动列表视图,一旦用户滚动到列表的末尾,我就会继续填充项目(我执行数据库查询)。如下
class EndlessScrollListener implements OnScrollListener{
/*code*/
}
listView.setOnScrollListener(new EndlessScrollListener());
/* the adapter */
public class HighlightedFieldsViewAdapter extends ArrayAdapter<T> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final BaseModel baseModel = objects.get(position);
if (baseModel != null) {
TextView uniqueIdView = (TextView) view.findViewById(R.id.row_child_unique_id);
ImageView imageView = (ImageView) view.findViewById(R.id.thumbnail);
try {
setFields(String.valueOf(baseModel.getShortId()), uniqueIdView);
assignThumbnail(baseModel, imageView);
view.setOnClickListener(createClickListener(baseModel, activityToLaunch));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
return view;
}
}
/* assignThumbNail method */
protected void assignThumbnail(BaseModel model, ImageView imageView) {
String current_photo_key = model.optString("current_photo_key");
if (cancelPotentialDownload(current_photo_key, imageView)) {
AssignThumbnailAsyncTask task = new AssignThumbnailAsyncTask(imageView, photoCaptureHelper);
ThumbnailDrawable drawable = new ThumbnailDrawable(task);
imageView.setImageDrawable(drawable);
task.execute(current_photo_key);
}
}
这在滚动时工作正常但在滚动一段时间后我得到一个java.lang.outOfMemory异常。我假设这个列表视图在添加了几千条记录之后变得太大了。
所以我的问题是,如何删除用户向上滚动的视线列表视图中出现的项目。