0
我在圖像中使用ListView,我也有圖像加載程序。問題是,當滾動速度很快時,圖像出現在錯誤的行上,在滾動停止後的很短時間內,每一件事都回到原位。從列到列跳轉的列表視圖中的圖像
這裏是我的適配器:
public class MyAdapter extends ArrayAdapter<MyObj>
{
int layoutResourceId;
List<MyObj> data;
Activity activity;
int rowViewId;
public MyAdapter(Activity activity, int layoutResourceId, List<MyObj> data)
{
super(activity, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.activity = activity;
this.data = data;
rowViewId = R.layout.my_layout.xml;
}
public static class ViewHolder
{
public TextView title;
public ImageView image;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
ViewHolder holder;
if (row == null)
{
LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(rowViewId, null);
holder = new ViewHolder();
holder.title = (TextView) row.findViewById(R.id.title);
holder.image = (ImageView) row.findViewById(R.id.image);
row.setTag(holder);
}
else
{
holder = (ViewHolder) row.getTag();
}
final MyObj obj = data.get(position);
if (event != null)
{
holder.title.setText(event.getTitle());
ImageLoader imageLoader = new ImageLoader();
imageLoader.loadImageFromAppServer(obj.getImageName(), holder.image);
}
return row;
}
}
有什麼事我可以做,以防止這種不必要的行爲?
當然,但你怎麼能真正做到這一點呢? – kabuto178
感謝您指出這一點,但我需要以前的圖像下載完成,才能得到這張圖片。 – vlio20
我認爲緩存圖像將是一個很好的解決方案...這種方式'loadImageFromAppServer'將花費很少的時間。 – vlio20