title: Adding PreferenceFragment to FragmentPagerAdapter
body: <p>I am trying to add a  <code>PreferenceFragment</code> to a <code>FragmentPagerAdapter</code>. </p>
  
  <p>My class extends <code>FragmentActivity</code>, I have tried <code>FragmentTransaction</code>, as shown below as well as trying to add to the container and can't seem to get anything to work. <em>No</em> errors are thrown, in fact nothing happens.</p>
  
  <p><strong>Main Activity:</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
      mViewPager = (ViewPager) findViewById(R.id.pager);
      mViewPager.setAdapter(mSectionsPagerAdapter);
  }
  </code></pre>
  
  <p><strong>activity_main.xml:</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;android.support.v4.view.ViewPager 
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity" &gt;
  &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>
  
  <p><strong>My Options menu selection:</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>android.app.FragmentManager fm;
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
      case R.id.menu_settings:
          JJSettings settings = new JJSettings();
          fm = getFragmentManager();
          FragmentTransaction fragTrans = fm.beginTransaction();
          // I also tried `replace()` here as well. Same 'nothing happens' result.
          fragTrans.add(settings, "settings");
          fragTrans.commit();
          return true;
      case R.id.menu_help:
          menuHelp();
          return true;
      default:
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p><strong>My settings</strong> <code>Fragment</code><strong>:</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public class JJSettings extends PreferenceFragment {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          addPreferencesFromResource(R.xml.settings);
      }
  }
  </code></pre>
  
  <p>My preference would be to stick with <code>Fragments</code> if possible, meaning I'd rather not extend <code>PreferenceActivity</code> or take the user to another Activity that calls the <code>PreferenceFragment</code>, if at all possible. I'm just hoping I missed something in my research.</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <pre><code>public class SectionsPagerAdapter extends FragmentPagerAdapter {
      private int _count = 2;
  
      public SectionsPagerAdapter(FragmentManager fm) { super(fm); }
  
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          return super.instantiateItem(container, position);
      }
  
      @Override
      public Fragment getItem(int position) {
          switch (position) {
          case 0:
              return new JJMainFragment();
          case 1:
              return new JJPendingFragment();
          default:
              return null;
          }
      }
  
      public void setCount(int count) { this._count = count; }
  
      @Override
      public int getCount() { return this._count; }
  
      @Override
      public CharSequence getPageTitle(int position) {
          switch (position) {
          case 0:
              return getString(R.string.c_list).toUpperCase(Locale.ENGLISH);
          case 1:
              return getString(R.string.c_pending).toUpperCase(Locale.ENGLISH);
          }
          return null;
      }
  }
  </code></pre>