So basically I want to populate the pages inside the ViewPager with separate XML layouts for each view position. I am currently doing this with
@Override public Object instantiateItem(View container, int position) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE); if(position == 0){ view = inflater.inflate(R.layout.main, null); ((ViewPager) container).addView(view, 0); } if(position == 1){ view = inflater.inflate(R.layout.main_second, null); ((ViewPager) container).addView(view, 0); } if(position == 2){ view = inflater.inflate(R.layout.main_third, null); ((ViewPager) container).addView(view, 0); } return view; }
The correct views are displayed first, but when I scroll through the ViewPager, the layout is hidden / destroyed. Why is this? Am I doing it wrong? please help and correct me.
Thanks. I love you. Wesley
source share