Skip to content

Instantly share code, notes, and snippets.

@burnix
Created February 16, 2016 00:21
Show Gist options
  • Save burnix/10d172aebc3ad7d0d2fe to your computer and use it in GitHub Desktop.
Save burnix/10d172aebc3ad7d0d2fe 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);
}
}
//как использовать
CustomPagerAdapter mCustomPagerAdapter = new CustomPagerAdapter(PoemnSlider.this, urls);
final ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mCustomPagerAdapter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment