I have an application which uses ViewPager. Inside the ViewPager I don't use Fragments, just inflated views (a RelativeLayout with some content). These views are pre-created and held in a List. I created simple PagerAdapter implementation which overrides methods getCount, isViewFromObject, instantiateItem and destroyItem.
When running on Android 2.x device it all runs fine and the method instantiateItem is called just once for each page that gets loaded as an offscreen page.
But when I run on ICS, the instantiateItem method gets called in a loop and the whole application stops responding. All I was able to realize was, that the instantiateItem method gets called as a result of a measurement. But I have no clue why on ICS the measurement gets called periodically in a loop and what can I do to stop it.
Here is a code snippet, but I believe there's nothing special on it:
mAdapter = new PagerAdapter()
{
@Override
public boolean isViewFromObject(View arg0, Object arg1)
{
return arg0 == arg1;
}
@Override
public int getCount()
{
return mPages.size();
}
@Override
public Object instantiateItem(ViewGroup container, int position)
{
View v = mPages.get(position);
boolean isChild = false;
for(int idx = 0; idx < getChildCount(); ++idx)
{
if(getChildAt(idx) == v)
{
isChild = true;
break;
}
}
if(!isChild)
addView(v);
return v;
}
@Override
public void destroyItem(ViewGroup container, int position, Object item)
{
removeView((View)item);
}
};
setAdapter(mAdapter);
This code gets place in an initialization method of a class which derives from ViewPager.
I would really appreciate any hint, because this issue is driving me crazy and makes my application unusable on ICS devices.