Exemplo n.º 1
0
  // 这里就是初始化ViewPagerItemView.如果ViewPagerItemView已经存在,
  // 重新reload,不存在new一个并且填充数据.
  @Override
  public Object instantiateItem(View container, int position) {
    ViewPagerItemView itemView;
    if (mHashMap.containsKey(position)) {
      itemView = mHashMap.get(position);
      itemView.reload();
    } else {
      itemView = new ViewPagerItemView(mContext);
      try {
        JSONObject dataObj = (JSONObject) mJsonArray.get(position);
        itemView.setData(dataObj);
      } catch (JSONException e) {
        e.printStackTrace();
      }
      mHashMap.put(position, itemView);
      ((ViewPager) container).addView(itemView);
    }

    return itemView;
  }
Exemplo n.º 2
0
 // 这里进行回收,当我们左右滑动的时候,会把早期的图片回收掉.
 @Override
 public void destroyItem(View container, int position, Object object) {
   ViewPagerItemView itemView = (ViewPagerItemView) object;
   itemView.recycle();
 }