0

I have extended the PagerAdapter class to create a custom adapter. In a strange way it behaves differently on different devices. For example on an Android 4.0.3 tablet, the viewpager tries to instantiate all the items which causes the OutOfMemoryError. However it works fine on an Android 4.2.2 phone.

Below you can find related parts of the pager adapter.

@Override
public Object instantiateItem(ViewGroup container, int position) {

    View page = page = viewRenderer.getView(context, position);;
    ((ViewPager)container).addView(page, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    return page;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    View view = (View) object;
    container.removeView(view);
    view = null;
}

If you have any suggestions, it will be really helpful. Thanks in advance.

sarslanhan
  • 517
  • 2
  • 7
  • 13
  • try setting `.setOffscreenPageLimit()`. With this you can manually tell the viewpager how many items to instantiate once. Maybe on different devices the default behaviour is different. – bogdan Jun 13 '13 at 12:25
  • I have tried this one actually. I guess it is not the problem. Becuase the value is already set to 1 which looks normal to me. – sarslanhan Jun 13 '13 at 12:28

0 Answers0