6

I am using Picasso for fetching images from server and displaying in viewpager, but I am getting some strange kind of error, some of my images are not getting shown, when I am loading image statically they are showing but when images are loading from server some of them getting disappeared, especially after 3.

Here is my ViewPagerAdapter.java:

public Object instantiateItem(final ViewGroup container, int position) {

    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = layoutInflater.inflate(R.layout.viewpager_item, container, false);
    /**
     * Loading the image view
     */
    // Locate the ImageView in viewpager_item.xml
    ImageView sliderItem = (ImageView) itemView.findViewById(R.id.viewpagerImageView1);

    // Capture position and set to the ImageView
  /*  if(requestCreatorListIterator.hasNext()) {
        requestCreatorListIterator.next().into(sliderItem);
    }*/
    slider[position].into(sliderItem);
    //sliderItem.setImageResource(slider[position]);

    // Add viewpager_item.xml to ViewPager
    ((ViewPager) container).addView(itemView);

    //http://stackoverflow.com/questions/21368693/how-to-do-circular-scrolling-on-viewpager
    ((ViewPager) container).addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            // skip fake page (first), go to last page
            if (position == 0) {
                ((ViewPager) container).setCurrentItem(slider.length - 2);
            }

            // skip fake page (last), go to first page
            if (position == slider.length - 1) {
                ((ViewPager) container).setCurrentItem(1); //notice how this jumps to position 1, and not position 0. Position 0 is the fake page!
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

}
JstnPwll
  • 8,585
  • 2
  • 33
  • 56
Ravi
  • 960
  • 1
  • 18
  • 41

1 Answers1

0

I finally found solution, Picasso has a problem that it uses lazy loading for fetching images, since I am loading images asynchronously before displaying, it s not able to load all the images.

Solution :: Using UIL (Universal Image Loader ), solved all my problem

Ravi
  • 960
  • 1
  • 18
  • 41
  • see tinyowl app in google play store and see image slider in home page, you will understand it better – Ravi Dec 21 '15 at 15:33