我有一个ListView,它包含一个ImageView和一个TextView。我是继承ArrayAdapter,以便我可以通过一个子类AsyncTask从互联网加载图像。迄今为止都很好。当我使用convertView时出现问题,当我没有问题时
的问题是,如果我尝试使用convertView,我有其中图像简单地回收进错行了问题。 (这是一个公司的标志,所以这是...不好。)
如果我不使用convertView,但是,图像丢失的用户滚动时。所以,如果他们向下滚动,备份,图像从互联网(数据使用这显然是不好的,电池寿命等)
有一个简单的办法解决这一问题,以便它不会重新加载每次从互联网加载,或移动图像?
下面是我使用的是什么至今:
public class SupplierAdapter extends ArrayAdapter<Supplier>{
int resource;
String response;
Context context;
public SupplierAdapter(Context context, int resource, List<Supplier> suppliers) {
super(context, resource, suppliers);
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LinearLayout view;
Supplier s = getItem(position);
if(convertView == null){
view = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi;
vi = (LayoutInflater) getContext().getSystemService(inflater);
vi.inflate(resource, view, true);
} else {
view = (LinearLayout) convertView;
}
ImageView iv = (ImageView) view.findViewById(R.id.thumbnail);
// s.getThumbnail returns a URL
new DownloadImageTask(iv).execute(s.getThumbnail());
TextView titleText =(TextView) view.findViewById(R.id.titleText);
titleText.setText(s.getTitle());
titleText.setTag(s.getId());
return view;
}
}
所有帮助非常感谢:)
你有没有考虑过使用SimpleAdapter和缓存? –
@丹,我没有。如何缓存?保存到SD卡?我不确定那将如何工作。 –
如果您要处理的不是字符串数组,而是SimpleAdapter更好。对于缓存,您可以将其保存到SD中,并有一些标准来检查更新。 –