title: Fragment in ViewPager shows nothing while returning from another fragment
body: <p>I have a ViewPager in the fragment named FragmentHome, and the viewpager contains fragments. Am using FragmentStatePagerAdapter for this. When the fragmentHome loads first the fragments in Viewpager show perfectly. I have another fragment named FragmentCountryList to select a country, according to that country the fragments in the viewpager to be refreshed/updated. Now The problem is after selecting the country, the country fragment is popped and returns to the FragmentHome, but, there nothing is showing in the view pager, if we scrolls the second page(fragment) can be viewed then scrolls back the first page(fragment) can be viewed.</p>
  
  <p>Am new with the FragmentStatePagerAdapter, so i couldn't rectify the reason for this problem. Please Help. The code i used gives below</p>
  
  <pre><code>public class FragmentHome extends WeGrabBaseFragment {
  private static String TAG = "FragmentHome";
  private HomeDealsDataClass homeDealsDataClass;//1, homeDealsDataClass2;
  private ViewPager viewPagerHome;
  private ImageView imgViewDealIndicator;
  private OnCitySelectedListener onCitySelectedListener;
  private FragPageAdapter fragAdapt;
  private ArrayList&lt;HomeDealsDataClass&gt; arrayListHomeData;
  private FragmentHomeDetails fragmentHomeDetails1,fragmentHomeDetails2;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Activity = (WeGrabBaseActivity) this.getActivity();
  }
  
  @Override
  public void onResume() {
      super.onResume();
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View v = inflater
              .inflate(R.layout.fragment_home, container, false);
      ((WeGrabMainActivity) Activity).showBottomBar();
      ((WeGrabMainActivity) Activity).setShowActionBar();
      ((WeGrabMainActivity) Activity).setHeading(PrefUtil.getCityName(Activity));
      ((WeGrabMainActivity) Activity).defaultButtonState();
      viewPagerHome = (ViewPager) v.findViewById(R.id.viewPagerHome);
      viewPagerHome.setOffscreenPageLimit(2);
      imgViewDealIndicator = (ImageView) v.findViewById(R.id.imgViewDealIndicator);
      Picasso.with(Activity).load(R.drawable.deals1).into(imgViewDealIndicator);
  
      viewPagerHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
              if (position == 0) {
                  Picasso.with(Activity).load(R.drawable.deals1).into(imgViewDealIndicator);
              } else if (position == 1) {
                  Picasso.with(Activity).load(R.drawable.deals2).into(imgViewDealIndicator);
              }
          }
  
          @Override
          public void onPageSelected(int position) {
              fragAdapt.notifyDataSetChanged();
          }
  
          @Override
          public void onPageScrollStateChanged(int state) {
  
          }
      });
  
      onCitySelectedListener = new OnCitySelectedListener() {
          @Override
          public void onCitySelected() {
              fetchFromWeb();
          }
      };
  
      fetchFromWeb();
      return v;
  }
  
  private void fetchFromWeb() {
      if (Activity.isNetworkAvailable()) {
          if (VolleyUtils.volleyEnabled) {
              Activity.startSpinwheel(false, true);
              JSONObject jsonObject = new JSONObject();
              try {
                  if (!PrefUtil.isGPSLocation(Activity)) {
                      jsonObject.putOpt(AppConstants.COUNTRY_ID, PrefUtil.getCountryCode(Activity));
                      jsonObject.putOpt(AppConstants.CITY_ID, PrefUtil.getCityCode(Activity));
  
                      Log.e(TAG, "Not GPS Home : " + jsonObject.toString());
                      CommandFactory commandFactory = new CommandFactory();
                      commandFactory.sendPostCommand(
                              AppConstants.WEGRAB_HOME_URL, jsonObject);
                  } else {
                      /*jsonObject.putOpt(AppConstants.COUNTRY_NAME, PrefUtil.getCountryName(Activity));
                      jsonObject.putOpt(AppConstants.CITY_NAME, PrefUtil.getCityName(Activity));*/
                      jsonObject.putOpt(AppConstants.COUNTRY_ID, "112");
                      jsonObject.putOpt(AppConstants.CITY_ID, "6");
  
                      CommandFactory commandFactory = new CommandFactory();
                      Log.e(TAG, "In  GPS Home : " + jsonObject.toString());
                      /*commandFactory.sendPostCommand(
                      AppConstants.WEGRAB_HOME_URL_GPS, jsonObject);*/
                      commandFactory.sendPostCommand(
                              AppConstants.WEGRAB_HOME_URL, jsonObject);
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  
  @Override
  public void onHomeDetailsPageDataLoadedSuccessfully(JSONObject jsonObject) {
      super.onHomeDetailsPageDataLoadedSuccessfully(jsonObject);
      Activity.stopSpinWheel();
      try {
          if (jsonObject != null) {
  
              if (jsonObject != null) {
                  fragAdapt = new FragPageAdapter(getFragmentManager());
                  viewPagerHome.setAdapter(fragAdapt);
                  JSONArray jsonArray = jsonObject.getJSONArray(AppConstants.DEALS);
                  arrayListHomeData = new ArrayList&lt;HomeDealsDataClass&gt;();
                  if(jsonArray.length() &gt; 0) {
                      viewPagerHome.setVisibility(View.VISIBLE);
                      for (int i = 0; i &lt; jsonArray.length(); i++) {
                          arrayListHomeData.add(new HomeDealsDataClass(jsonArray.getJSONObject(i)));
                      }
                      fragAdapt.notifyDataSetChanged();
                  }else{
                      viewPagerHome.setVisibility(View.GONE);
                  }
              }
          }
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  @Override
  public void onHomeDetailsPageDataLoadedFailed(JSONObject jsonObject) {
      super.onHomeDetailsPageDataLoadedFailed(jsonObject);
      Activity.stopSpinWheel();
  }
  
  private class FragPageAdapter extends FragmentStatePagerAdapter {
      FragPageAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int pos) {
          switch (pos) {
  
              case 0:
                  Log.e(TAG,"Returns Fragment Home deals 1");
                  fragmentHomeDetails1 = FragmentHomeDetails.newInstance(arrayListHomeData.get(0));
                  return fragmentHomeDetails1;
              case 1:
                  Log.e(TAG,"Returns Fragment Home deals 2");
                  fragmentHomeDetails2 =  FragmentHomeDetails.newInstance(arrayListHomeData.get(1));
                  return fragmentHomeDetails2;
              default:
                  return null;
          }
      }
  
      @Override
      public int getItemPosition(Object object) {
          return POSITION_NONE;
      }
  
      @Override
      public int getCount() {
          if(arrayListHomeData != null)
              return arrayListHomeData.size();
          else
              return 0;
      }
  }
  </code></pre>
  
  <p>}</p>