Java tutorial
/* * Copyright 2014 trinea.cn All right reserved. This software is the * confidential and proprietary information of trinea.cn ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with trinea.cn. */ package com.xxjwd.adapter; import java.util.List; import android.content.Context; import android.graphics.Bitmap; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; /** * ImagePagerAdapter * * @author <a href="http://www.trinea.cn" target="_blank">Trinea</a> 2014-2-23 */ public class ImagePagerAdapter extends PagerAdapter { private Context context; private List<Bitmap> imageList; public ImagePagerAdapter(Context context, List<Bitmap> imageIdList){ this.context = context; this.imageList = imageIdList; } @Override public int getCount() { if (imageList == null ) return 0; else return imageList.size(); } @Override public boolean isViewFromObject(View view, Object object) { return (view == object); } @Override public Object instantiateItem(ViewGroup container, int position) { ImageView imageView = new ImageView(context); imageView.setImageBitmap(imageList.get(position)); ((ViewPager)container).addView(imageView, 0); return imageView; } @Override public void destroyItem(ViewGroup container, int position, Object object) { ((ViewPager)container).removeView((ImageView)object); } }