コード例 #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      tag = new Tag();
      convertView = inflater.inflate(R.layout.item_main_info, null);
      tag.imgIcon = (ImageView) convertView.findViewById(R.id.item_infoIcon);
      tag.labTitle = (TextView) convertView.findViewById(R.id.item_infoTitle);
      tag.labDesc = (TextView) convertView.findViewById(R.id.item_infoDesc);
      tag.labPrice = (TextView) convertView.findViewById(R.id.item_infoPrice);
      tag.labTime = (TextView) convertView.findViewById(R.id.item_infoTime);
      tag.labAddress = (TextView) convertView.findViewById(R.id.item_infoAddress);
      convertView.setTag(tag);
    } else {
      tag = (Tag) convertView.getTag();
    }
    String iconUrl = null;
    FavoriteEntity entity = list.get(position);
    if (entity != null) {
      iconUrl = entity.getImages();
      if (iconUrl != null) {
        List<String> icons = ParseStringUtil.strToArray(iconUrl, "|");
        if (icons != null && icons.size() > 0) {
          iconUrl = icons.get(0).trim(); // 取得第一个图片路径
          if (iconUrl != null && !iconUrl.equals("")) {
            iconUrl = ContantURL.getUploadSmallImageUrl(iconUrl);
          }
        }
      }
      tag.labTitle.setText(entity.getTitle());
      tag.labDesc.setText(entity.getDescription());
      tag.labAddress.setText(entity.getAddress());
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
      if (entity.getUpdateDate() != null) {
        tag.labTime.setText(dateFormat.format(entity.getUpdateDate()));
      }
      tag.labPrice.setText(entity.getPrice() + "");
    }
    // 异步加载图片
    /** 显示图片 参数1:图片url 参数2:显示图片的控件 参数3:显示图片的设置 参数4:监听器 */
    imageLoader.displayImage(iconUrl, tag.imgIcon, options, null);
    //		final View tempview = convertView;
    //		if(iconUrl != null && !iconUrl.equals("")){
    //			tag.imgIcon.setTag(iconUrl);
    //			Bitmap bitmap = null;
    //			String imgUrl = iconUrl;
    //			if(imgUrl != null){
    //				// 延迟加载图片
    //				bitmap = imageLoader.loadData(iconUrl, new AsyncImageLoader.LoadDataCallback<Bitmap>() {
    //					@Override
    //					public void dataLoaded(String arg0, Bitmap arg1) {
    //						tag.imgIcon.setImageBitmap(arg1);
    //						ImageView imageViewByTag = (ImageView) tempview
    //						.findViewWithTag(arg0);
    //						if (imageViewByTag != null && arg1!=null) {
    //							imageViewByTag.setImageBitmap(arg1);
    //						}
    //
    //					}
    //				});
    //			}
    //			if(bitmap == null){
    //				tag.imgIcon.setImageResource(R.drawable.image_no_bg_small);
    //			}else{
    //				tag.imgIcon.setImageBitmap(bitmap);
    //			}
    //		}else{
    //			tag.imgIcon.setImageResource(R.drawable.image_no_bg_small);
    //		}

    return convertView;
  }