public class ViewPagerAdapter extends PagerAdapter {
private ArrayList<GroupAlbumPhotoBean> image_list;
private LayoutInflater inflater;
private ViewPagerItemClickListener callback;
public GroupViewPagerAdapter(Context context,
ArrayList<GroupAlbumPhotoBean> image_list,
ViewPagerItemClickListener callback) {
this.image_list = image_list;
inflater = LayoutInflater.from(context);
this.callback = callback;
}
@Override
public int getCount() {
if (image_list != null && image_list.size() > 0) {
return image_list.size();
} else {
return 0;
}
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
View itemview = inflater.inflate(R.layout.activity_show_big_pic_item,
null);
PhotoView imageView = (PhotoView) itemview
.findViewById(R.id.iv_show_big_pic);
ImageUtils.setImage(image_list.get(position).getUrl(), imageView);
imageView.setOnPhotoTapListener(new OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float x, float y) {
callback.onItemClick(position);
}
});
((ViewPager) container).addView(itemview, 0);
return itemview;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
原文链接:http://www.apkbus.com/blog-160625-59777.html
打开App,阅读手记