SHARE
TWEET

Untitled

a guest Jun 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ViewPagerAdapter extends PagerAdapter {
  2.     private Context context;
  3.     private String[] imageUrls;
  4.  
  5.     ViewPagerAdapter(Context context, String[] imageUrls) {
  6.         this.context = context;
  7.         this.imageUrls = imageUrls;
  8.     }
  9.  
  10.     @Override
  11.     public int getCount()
  12.     {
  13.         return imageUrls.length;
  14.     }
  15.  
  16.     @Override
  17.     public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
  18.         return view == object;
  19.     }
  20.  
  21.     @NonNull
  22.     @Override
  23.     public Object instantiateItem(@NonNull ViewGroup container, int position) {
  24.         ImageView imageView = new ImageView(context);
  25.         Picasso.get()
  26.                 .load(imageUrls[position])
  27.                 .fit()
  28.                 .centerCrop()
  29.                 .into(imageView);
  30.         container.addView(imageView);
  31.  
  32.         return imageView;
  33.     }
  34.  
  35.     @Override
  36.     public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
  37.         container.removeView((View) object);
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top