标签:listen ret and android tar roi dem tee 数组
package com.tree.schoollife.adapter;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;
import java.util.List;
/**
* Created by tree on 2016/11/10.
*/
public class ViewPagerAdapter extends PagerAdapter {
private List<ImageView> mData;
public ViewPagerAdapter(List<ImageView> mData) {
this.mData = mData;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
//对ViewPager页号求模取出View列表中要显示的项
position %= mData.size();
if (position<0){
position = mData.size()+position;
}
ImageView view = mData.get(position);
//如果View已经在之前添加到了一个父组件,则必须先remove,否则会抛出IllegalStateException。
ViewParent vp =view.getParent();
if (vp!=null){
ViewGroup parent = (ViewGroup)vp;
parent.removeView(view);
}
container.addView(view);
//add listeners here if necessary
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
//Warning:不要在这里调用removeView
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
}
标签:listen ret and android tar roi dem tee 数组
原文地址:http://www.cnblogs.com/Juladoe/p/6135536.html