Created
February 23, 2016 12:56
-
-
Save burnix/19e6e4969f70f3bdc1e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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