@Override
  public Fragment getItem(int position) {
    int pageId = mTabConfig.getVisibleItem(position).getId();
    AbstractGroupingFactory factory = getGroupingFactoryForId(pageId);

    TaskListFragment fragment = TaskListFragment.newInstance(position, mTwoPaneLayout);
    fragment.setExpandableGroupDescriptor(factory.getExpandableGroupDescriptor());
    fragment.setPageId(pageId);
    return fragment;
  }
  /**
   * Create a new {@link TaskGroupPagerAdapter}.
   *
   * @param fm A {@link FragmentManager}
   * @param groupingFactories An array of {@link AbstractGroupingFactory}.
   * @param context A context to access resources
   * @param tabRes The resource id of an XML resource that describes the items of the pager
   * @throws XmlObjectPullParserException
   * @throws IOException
   * @throws XmlPullParserException
   */
  @SuppressLint("NewApi")
  public TaskGroupPagerAdapter(
      FragmentManager fm, AbstractGroupingFactory[] groupingFactories, Context context, int tabRes)
      throws XmlPullParserException, IOException, XmlObjectPullParserException {
    super(fm);
    mContext = context;

    mTabConfig = TabConfig.load(context, tabRes);

    for (AbstractGroupingFactory factory : groupingFactories) {
      mGroupingFactories.put(factory.getId(), factory);
    }
  }