有效使用BaseAdapter
时,我使用ViewHolder来保存要回收的物品。
通常情况下,我使用ImageLoader
库加载图像,这没关系。
这次我从ByteArray加载图像,但是当我加载它们并滚动ListView时,我弄得一团糟。
这是我的代码:
class ViewHolderItem {
CircularImageView circularImageView1;
TextView textView1, textView2;
ProgressBar progressBar1;
}
@Override
public View getView(int position, View convertView, ViewGroup var3) {
Scuola scuolaItem = lista.get(position);
ViewHolderItem viewHolderItem;
if(convertView == null) {
convertView = ((LayoutInflater)getSystemService("layout_inflater")).inflate(R.layout.item_elencoscuole, var3, false);
viewHolderItem = new ViewHolderItem();
viewHolderItem.textView1 = (TextView)convertView.findViewById(R.id.textView1);
viewHolderItem.textView2 = (TextView)convertView.findViewById(R.id.textView2);
viewHolderItem.progressBar1 = (ProgressBar)convertView.findViewById(R.id.progressBar1);
viewHolderItem.circularImageView1 = (CircularImageView)convertView.findViewById(R.id.circularImageView1);
convertView.setTag(viewHolderItem);
} else {
viewHolderItem = (ViewHolderItem)convertView.getTag();
}
viewHolderItem.textView1.setText(scuolaItem.getNome());
viewHolderItem.textView2.setText(scuolaItem.getDistanzaDaOrigine() + " " + scuola.getUnitaDistanza());
byte[] imageAsBytes = Base64.decode(scuolaItem.getLogoFile(), Base64.DEFAULT);
viewHolderItem.circularImageView1.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));
viewHolderItem.progressBar1.setVisibility(View.GONE);
return convertView;
}
我该如何解决?
感谢。