title: View pager lost its content while switch to tabs in fragment tab host
body: <p>I am facing the very weird problem,i found the similar kind of problem over the net but none of the solution helps me to get rid of this.</p>
  
  <p><strong>Problem ::</strong> </p>
  
  <p>I am having a one fragment which have 3 tabs,(tabs created using fragment tab host).Now every tabs have different fragment.</p>
  
  <p>From first tab,i have set one fragment where i have used view pager and circle page indicator to display the images with dots(circle).</p>
  
  <p>Now when i swipe the image from 1st to 2nd then 3rd and so on,it works fine.
  But after reaching on image 2nd,when i click on tab2 and again came back to tab1,my images lost.</p>
  
  <p>Your guidance or any help/links  will be appreciated..<br>
  Many many thanks in advance.</p>
  
  <p>For your understanding here i am posting code below ::</p>
  
  <p><strong>FragmentwithTabHost ::</strong> </p>
  
  <pre><code>public class FragmentwithTabHost extends Fragment{
  
      private View rootView;
       private FragmentTabHost mTabHost;
       private Context mContext;
      public FragmentwithTabHost() {
      }
  
      public FragmentwithTabHost(Context ctx) {
          mContext=getActivity();
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          rootView = inflater.inflate(R.layout.mycardswithtabs, container,
                  false);
  
          mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost);
  
          mTabHost.setup(getActivity(), getChildFragmentManager(), android.R.id.tabcontent);
          mTabHost.setBackground(getActivity().getResources().getDrawable(R.drawable.normal));
          mTabHost.addTab(
                  mTabHost.newTabSpec("tab1").setIndicator("tab1", null),
                  Fragment1.class, null);
          mTabHost.addTab(
                  mTabHost.newTabSpec("tab2").setIndicator("tab2", null),
                  Fragment2.class, null);
          mTabHost.addTab(
                  mTabHost.newTabSpec("tab3").setIndicator("tab3", null),
                  Fragment3.class, null);
          return rootView;
      }
  }
  </code></pre>
  
  <p><strong>Fragment1 ::</strong> </p>
  
  <pre><code>public class Fragment1 extends Fragment{
  
      //  private Context mContext;
      private View rootView;
  
      SlidesFragmentAdapter mAdapter;
      ViewPager mPager;
      PageIndicator mIndicator;
      LinearLayout llSponseredImage,llSponserdByText;
      ImageView imgsponser1,imgsponser2,imgsponser3,imgsponser4;
      public Fragment1() {
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          rootView = inflater.inflate(R.layout.my_card, container,false);
  
          mAdapter = new SlidesFragmentAdapter(getActivity()
                  .getSupportFragmentManager());
  
          llSponseredImage=(LinearLayout)rootView.findViewById(R.id.mycardbottomViewSponseredImage);
          llSponserdByText=(LinearLayout)rootView.findViewById(R.id.mycardbottomsponsredby);
  
          imgsponser1=(ImageView)rootView.findViewById(R.id.imgsponser1);
          imgsponser2=(ImageView)rootView.findViewById(R.id.imgsponser2);
          imgsponser3=(ImageView)rootView.findViewById(R.id.imgsponser3);
          imgsponser4=(ImageView)rootView.findViewById(R.id.imgsponser4);
  
          mPager = (ViewPager) rootView.findViewById(R.id.pager);
          mPager.setOffscreenPageLimit(4);
          mPager.setClipToPadding(false);
          mPager.setPageMargin(12);
          mPager.setAdapter(mAdapter);
  
          mIndicator = (CirclePageIndicator) rootView.findViewById(R.id.indicator);
          mIndicator.setViewPager(mPager);
          ((CirclePageIndicator) mIndicator).setSnap(true);
  
          mPager.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  System.out.println("3242353652523");
                  MyCardsWithOffersFragment myCardsWithOffersFragment=new MyCardsWithOffersFragment();
              }
          });
          mIndicator
          .setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
              @Override
              public void onPageSelected(int position) {
                  /*Toast.makeText(getActivity(),
                          "Changed to page " + position,
                          Toast.LENGTH_SHORT).show();*/
                  if(position==0 || position==2){
                      llSponseredImage.setVisibility(View.GONE);
                      llSponserdByText.setVisibility(View.GONE);
                  }else if(position==1){
                      llSponseredImage.setVisibility(View.VISIBLE);
                      llSponserdByText.setVisibility(View.VISIBLE);
  
                      imgsponser1.setImageResource(R.drawable.sponser1);
                      imgsponser2.setImageResource(R.drawable.sponser2);
                      imgsponser3.setImageResource(R.drawable.sponser3);
                      imgsponser4.setImageResource(R.drawable.sponser4);
                  }else if(position==3){
                      llSponseredImage.setVisibility(View.VISIBLE);
                      llSponserdByText.setVisibility(View.VISIBLE);
  
                      imgsponser1.setImageResource(R.drawable.sponser5);
                      imgsponser2.setImageResource(R.drawable.sponser6);
                      imgsponser3.setImageResource(R.drawable.sponser7);
                      imgsponser4.setImageResource(R.drawable.sponser8);
                  }
              }
  
              @Override
              public void onPageScrolled(int position,
                      float positionOffset, int positionOffsetPixels) {
              }
  
              @Override
              public void onPageScrollStateChanged(int state) {
              }
          });
  
          return rootView;
      }
  
      public class SlidesFragmentAdapter extends FragmentStatePagerAdapter implements IconPagerAdapter {
  
          private int[] Images = new int[] { R.drawable.first_image, R.drawable.second_image,
                  R.drawable.third_image, R.drawable.four_image
  
          };
  
          private int[] ICONS = new int[] { R.drawable.first_image, R.drawable.second_image,
                  R.drawable.third_image, R.drawable.four_image };
  
          private int mCount = Images.length;
  
          public SlidesFragmentAdapter(android.support.v4.app.FragmentManager fragmentManager) {
              super(fragmentManager);
          }
  
          @Override
          public Fragment getItem(int position) {
              return new DemoFragment(Images[position]);
          }
  
          @Override
          public int getCount() {
              return mCount;
          }
  
          @Override
          public int getIconResId(int index) {
              return ICONS[index % ICONS.length];
          }
          public float GetPageWidth (int position) {
              return 0.93f;
          }  
          public void setCount(int count) {
              if (count &gt; 0 &amp;&amp; count &lt;= 10) {
                  mCount = count;
                  notifyDataSetChanged();
              }
          }
      }
  }
  </code></pre>