title: When calling getItem() on FragmentPagerAdapter it returns an empty fragment
body: <p>I am having problems using the FragmentPagerAdapter.
  I want to retrieve the data from fragments in a View Pager. When I call the getItem() Method it returns a Fragment, but it doesn’t create the fragment. All the fragments variables are null. What do I need to do to instantiate the fragment? 
  This is my adapter.</p>
  
  <pre><code>public class SubItemAdapter extends FragmentPagerAdapter implements Serializable {
      List&lt;Item&gt; itemList = new ArrayList&lt;&gt;();
      int layout;
  
  
      public SubItemAdapter(FragmentManager mgr, List&lt;? extends Item&gt; items, int layout) {
          super(mgr); 
          itemList.addAll(items);
          this.layout = layout; 
  
      }
  
      @Override
      public int getCount() {
          return itemList.size();
      }
  
      @Override
      public SubItemFragment getItem(int position) {
          return SubItemFragment.newInstance(itemList.get(position), layout); 
      }
  }
  </code></pre>
  
  <p>This is the fragment in the viewpager.</p>
  
  <pre><code>public class SubItemFragment extends Fragment {
  Item item;
  View view;
  Context mContext;
  private static final int RC_BARCODE_CAPTURE = 9001;
  private static final String ITEM_KEY = "item";
  private static final String LAYOUT_PAGER_KEY = "layout";
  
  public static SubItemFragment newInstance(Item item, int layout) {
      SubItemFragment frag = new SubItemFragment();
      Bundle args = new Bundle();
      args.putSerializable(ITEM_KEY, item);
      args.putInt(LAYOUT_PAGER_KEY, layout);
      frag.setArguments(args);
      return (frag);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater,
                           ViewGroup container,
                           Bundle savedInstanceState) {
  
      int layout = getArguments().getInt(LAYOUT_PAGER_KEY);
      view = inflater.inflate(layout, container, false);
      item = (Item) getArguments().getSerializable(ITEM_KEY); 
      mContext = getContext();
      /* Populate the fragment with data
      . . .
      */
      return (view);
      }
  
      public Item getItem() {
          item.retrieve_data_and_populate_item();
          return item;
      }
  }
  </code></pre>
  
  <p>I don’t have a great understanding of how the ViewPager works but from what I understand the reason the fragment is coming back without any variables set is because the ViewPager isn’t attaching the fragments. How do I get the getItem(int position) function to return an initialized fragment?
  If my question isn’t clear enough or if you need to see more code, just let me know.
  Thanks in advance.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I am setting the adapter in the parent fragment. Here is the code for adding the ViewPager:</p>
  
  <pre><code>public class General_Fragment implements SubItemFragment.subItemListener {
  
      private static final int LAYOUT_PAGER_KEY = R.layout.sub_form_meter_read;
      private SubItemAdapter mAdapter;
      private WrapViewPager mPager;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
      final View rootView = inflater.inflate(R.layout.workorder_detail, container, false);
      meters = getMeterList();
      mPager = rootView.findViewById(R.id.meter_list);
      mPager.addOnPageChangeListener(getOnPageListener());
      mAdapter = buildAdapter(meters);
      mPager.setAdapter(mAdapter);
      return rootView;
      }
  
      /*. . .*/ 
  
      private SubItemAdapter buildAdapter(List&lt;? extends Item&gt; items) {
          return new SubItemAdapter(getChildFragmentManager(), //Fragment View
                  items, //Item to get data from
                  LAYOUT_PAGER_KEY
          );
      }
  
  }
  </code></pre>
  
  <p>I don't think my problem lies in initializing the adapter because It does display but when I go to retrieve data from the fragment that's where it crashes because of the empty fragment</p>