title: How can I add a fragment to a ViewPager? addView crashes my app
body: <p>I'm using the default Swipe Tab Fragment code that Android starts with when you start a new Android application. I've figured out how to modify my data and use the tabs, but I haven't figured out how to add a simple fragment to what's already there. I wanted to add a infobar on the top of the tabs or right below them. I'm sure it's simple, I just can't figure out how lol. I learn by examples.</p>
  
  <p>I've tried adding a view to viewpager, but my app is crashing, and I believe I'm totally doing it wrong.</p>
  
  <p>In my MainActivity:
  ...</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      // Set up the action bar.
      final ActionBar actionBar = getActionBar();
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
      mSectionsPagerAdapter = new SectionsPagerAdapter(
              getSupportFragmentManager());
  
      // Set up the ViewPager with the sections adapter.
      mViewPager = (ViewPager) findViewById(R.id.pager);
      mViewPager.setAdapter(mSectionsPagerAdapter);
      SubBarFragment infobar = new SubBarFragment();
      mViewPager.addView(infobar.getView());      
  .....[extra code for menus and things]
  
  public class SectionsPagerAdapter extends FragmentPagerAdapter {
  
      public SectionsPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
  ....[code to show specific tabs and return the tab's fragment]
  </code></pre>
  
  <p>infobarfragment.java</p>
  
  <pre><code>public class InfobarFragment extends Fragment {
  
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.infobar, container, false);
          return view;
        }
  
  }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &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;
  </code></pre>
  
  <p>infobar.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
      &lt;ImageView
          android:id="@+id/imageView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_wifi" /&gt;
  
      &lt;TextView
          android:id="@+id/statusText1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:text="Wifi Status Information" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>