1

作为对 a 的有效使用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;
    }

我该如何解决?

谢谢。

4

0 回答 0