@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {
      // 使用自定义的list_items作为Layout
      convertView = mInflater.inflate(mResource, parent, false);
      // 减少findView的次数
      holder = new ViewHolder();
      // 初始化布局中的元素
      holder.itemsIcon = ((ImageView) convertView.findViewById(mTo[0]));
      holder.itemsTitle = ((TextView) convertView.findViewById(mTo[1]));
      holder.itemsText = ((TextView) convertView.findViewById(mTo[2]));
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    // 获取该行的数据
    @SuppressWarnings("unchecked")
    final Map<String, Object> obj = (Map<String, Object>) mData.get(position);
    String imageUrl = (String) obj.get("itemsIcon");
    holder.itemsTitle.setText((String) obj.get("itemsTitle"));
    holder.itemsText.setText((String) obj.get("itemsText"));
    // 设置加载中的View
    mAbImageDownloader.setLoadingView(convertView.findViewById(R.id.progressBar));
    // 图片的下载
    mAbImageDownloader.display(holder.itemsIcon, imageUrl);

    return convertView;
  }
Esempio n. 2
0
  private void initViewAdapter(ArrayList<News> list2) {
    // TODO Auto-generated method stub
    ArrayList<View> list = new ArrayList<View>();

    LinearLayout.LayoutParams params =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    AbImageDownloader mAbImageDownloader = new AbImageDownloader(context);
    for (int i = 0; i < 3; i++) {
      ImageView imageView = new ImageView(context);
      imageView.setLayoutParams(params);
      imageView.setScaleType(ScaleType.FIT_XY);
      mAbImageDownloader.display(imageView, list2.get(i).getImgUrl1());
      list.add(imageView);
    }
    viewPager1.setAdapter(new ViewAdapter(list));
  }
 /**
  * 构造方法
  *
  * @param context
  * @param data 列表展现的数据
  * @param resource 单行的布局
  * @param from Map中的key
  * @param to view的id
  */
 public ImageListAdapter(Context context, List data, int resource, String[] from, int[] to) {
   this.mContext = context;
   this.mData = data;
   this.mResource = resource;
   this.mFrom = from;
   this.mTo = to;
   // 用于将xml转为View
   this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   // 图片下载器
   mAbImageDownloader = new AbImageDownloader(mContext);
   mAbImageDownloader.setWidth(240);
   mAbImageDownloader.setHeight(400);
   mAbImageDownloader.setType(AbConstant.SCALEIMG);
   mAbImageDownloader.setLoadingImage(R.drawable.image_loading);
   mAbImageDownloader.setErrorImage(R.drawable.image_error);
   mAbImageDownloader.setNoImage(R.drawable.image_no);
   // mAbImageDownloader.setAnimation(true);
 }