【发布时间】:2013-09-27 08:45:48
【问题描述】:
我使用ArrayAdapter 填写ListView。
我用于getView 的代码如下:
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if(rowView ==null){
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.rowlayout_member, parent, false);
}
TextView tvName = (TextView) rowView.findViewById(R.id.label);
TextView tvSurname = (TextView) rowView.findViewById(R.id.label1);
ImageView ivPhoto = (ImageView) rowView.findViewById(R.id.icon);
setRow(tvName ,tvSurname ,ivPhoto,name[position],surname[position],pics[position],); // name, surname and pics are the array of String passed to the adapter.
return rowView;
}
private void setRow(TextView tv1, TextView tv2, ImageView iv, String name, String surname, String photo){
iv.setImageResource(R.drawable.sagoma);
tv1.setText(String.valueOf(name));
tv2.setText(String.valueOf(surname)); //la quantità la devo prendere da un array di
if(photo!=null)
imageLoader.displayImage(basePath+photo, iv, options);
}
这工作正常,但我有以下问题:
由于我使用的是convertView,视图会被回收,所以当我上下滚动时,可能会发生一些图像被推到我的ListView 的错误行中,尤其是当我快速滚动时。
如何在不牺牲View的回收利用的情况下避免这个问题?
注意:
imageLoader.displayImage(basePath+immagine, iv, options);
来自通用图像加载器库。此方法调用一个线程来加载图像。如果不再需要图像(导致滚动),则线程停止。
【问题讨论】:
标签: android listview android-listview android-adapter universal-image-loader