Comment puis-je ajouter un fragment d'un ViewPager? addView plante mon app

Je suis en utilisant la valeur par défaut de Balayage Onglet Fragment de code qui Android commence avec quand vous commencez une nouvelle application Android. J'ai trouvé comment modifier mes données et utilisez les onglets, mais je n'ai pas trouvé comment ajouter un simple fragment de ce qui existe déjà. Je voulais ajouter une barre d'informations en haut des onglets à droite ou au-dessous d'eux. Je suis sûr que c'est simple, j'ai juste ne peux pas comprendre comment lol. J'apprends par des exemples.

J'ai essayé d'ajouter une vue à viewpager, mais mon application est en panne, et je crois que je suis totalement de faire le mal.

Dans mon MainActivity:
...

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]

infobarfragment.java

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;
      }

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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" />

infobar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_wifi" />

    <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" />

</LinearLayout>
vous disposez d'un adaptateur pour le ViewPager, utilisez la méthode getItem / instanciateItem (dépend de ce que vous utilisez: des fragments ou des simples points de vue). la méthode donne le viewpager objet fallait à tous points de vue.
pouvez-vous retourner plus d'un fragment de la carte? J'ai compris comment ajouter un fragment à l'aide de Santhosh de l'aider, mais il la traite comme une autre "page" que je puisse glisser à travers. Je veux qu'il soit persistant n'importe quelle page je suis sur. J'avais voulu qu'il soit au-dessus des onglets, mais je ne pense pas que ce soit possible. Donc, en ayant au-dessous des onglets est bien pour le moment, je suppose. Pensées?

OriginalL'auteur CREW | 2013-04-26