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.