Skip to content

Instantly share code, notes, and snippets.

@burnix
Created February 23, 2016 12:56
Show Gist options
  • Save burnix/19e6e4969f70f3bdc1e5 to your computer and use it in GitHub Desktop.
Save burnix/19e6e4969f70f3bdc1e5 to your computer and use it in GitHub Desktop.
class CustomPagerAdapter extends PagerAdapter {
Context mContext;
LayoutInflater mLayoutInflater;
String[] mResources;
public CustomPagerAdapter(Context context, String[] mResources) {
mContext = context;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mResources = mResources;
}
@Override
public int getCount() {
return mResources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ( object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = mLayoutInflater.inflate(R.layout.pager_item, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
Picasso.with(mContext)
.load(mResources[position])
.into(imageView);
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout) object);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment