예제 #1
0
  @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;
  }
예제 #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));
  }