title: Android: tabs with swipe not showing listfragment
body: <p>I'm dealing with this tutorial: <a href="http://www.lucazanini.eu/2012/android/tabs-and-swipe-views/?lang=en" rel="nofollow">http://www.lucazanini.eu/2012/android/tabs-and-swipe-views/?lang=en</a> .
  The problem is that if I set as layout of the tab a simple static layout, like this (as the tutorial does), everything works fine: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/tab1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:gravity="center"&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:text="@string/body1" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But I need the tab to be a ListFragment, and the matter is that my ListFragment shows nothing at all.
  Here is the code. Don't desperate: I put lots of code but I think you will probably just need to look at the classes SongsFragment and SongsListAdapter (well, I am not sure because I were it I would not write here, however I suppose it because with a static layout everything works fine!) </p>
  
  <p>EDIT: I post just one listfragment in the exemple, however it seems that every listfragment has the same issue</p>
  
  <p><strong>EDIT: probably the problem is that I need to use a method to show the fragment when the tab is selected</strong></p>
  
  <p><em><strong>THANKS A LOT</em></strong></p>
  
  <p>Activity: </p>
  
  <pre><code>import android.app.ActionBar;
  import android.app.ActionBar.Tab;
  import android.app.FragmentTransaction;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.view.ViewPager;
  
  public class PlayerActivity extends FragmentActivity implements
          ActionBar.TabListener {
  
      CollectionPagerAdapter mCollectionPagerAdapter;
      ViewPager mViewPager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          mCollectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());
  
          final ActionBar actionBar = getActionBar();
          actionBar.setHomeButtonEnabled(false);
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          mViewPager = (ViewPager) findViewById(R.id.pager);
          mViewPager.setAdapter(mCollectionPagerAdapter);
          mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
              @Override
              public void onPageSelected(int position) {
                  // When swiping between different app sections, select
                  // the corresponding tab.
                  // We can also use ActionBar.Tab#select() to do this if
                  // we have a reference to the Tab.
                  actionBar.setSelectedNavigationItem(position);
              }
          });
  
          for (int i = 0; i &lt; mCollectionPagerAdapter.getCount(); i++) {
              actionBar.addTab(actionBar.newTab()
                      .setText(mCollectionPagerAdapter.getPageTitle(i))
                      .setTabListener(this));
          }
  
      }
  
      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
          mViewPager.setCurrentItem(tab.getPosition());
      }
  
      public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
          // TODO Auto-generated method stub
  
      }
  
      public void onTabReselected(Tab tab, FragmentTransaction ft) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>
  
  <p>SongsFragment</p>
  
  <pre><code>    import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.ListFragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ListView;
  
  public class SongsFragment extends ListFragment {
  
  import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.ListFragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ListView;
  
  public class SongsFragment extends ListFragment {
  
      List&lt;String[]&gt; songs;
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
  
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);    
  
          songs = SongsDataSource.getInstance().getAllSongs();
  
          List&lt;String[]&gt; values = new ArrayList&lt;String[]&gt;();
  
          if (songs.size() == 0) {
              values.add(new String[] { "No files found", "Try to update your database", "" });
          }
  
          for (String[] song : songs) {
              values.add(new String[] { song[1], song[2], song[0] });
          }
  
          SongsListAdapter adapter = new SongsListAdapter(getActivity().getApplicationContext(),
                  R.layout.songs, R.id.songsFragment_titleTextView,R.id.songsFragment_artistTextView, values);
  
          setListAdapter(adapter);
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.songs, container, false); 
          return view;
      }
  
  
  
      @Override
      public void onListItemClick(ListView l, View v, int position, long id) {
      }
  
  }
  </code></pre>
  
  <p>SongsListAdapter</p>
  
  <pre><code>import java.util.List;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.TextView;
  
  
  
  public class SongsListAdapter extends ArrayAdapter&lt;List&lt;String[]&gt;&gt; {
      private final Context context;
      private final List&lt;String[]&gt; values;
      private final Integer listViewId;
      private final Integer titleTextViewId;
      private final Integer artistTextViewId;
  
      public SongsListAdapter(Context context, Integer listViewId, Integer titleTextViewId, 
              Integer artistTextViewId, List values) {
          super(context, listViewId, values);
          this.context = context;
          this.listViewId = listViewId;
          this.values = values;
          this.titleTextViewId = titleTextViewId;
          this.artistTextViewId = artistTextViewId;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View rowView = inflater.inflate(listViewId, parent, false);
          TextView titleView = (TextView) rowView.findViewById(titleTextViewId);
          TextView artistView = (TextView) rowView.findViewById(artistTextViewId);
          titleView.setText(values.get(position)[0]);
          artistView.setText(values.get(position)[1]);
          return rowView;
      }
  }
  </code></pre>
  
  <p>PagerAdapter </p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  
  
  public class CollectionPagerAdapter extends FragmentPagerAdapter {
  
      public CollectionPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int i) {
          Fragment fragment = new TabFragment();
          Bundle args = new Bundle();
          args.putInt(TabFragment.ARG_OBJECT, i);
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public int getCount() {
          return MyApplication.getInstance().infoFragments.length;
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          String tabLabel = null;
  
          if(0 &lt;= position &amp;&amp; position &lt; MyApplication.getInstance().infoFragments.length) {
              tabLabel = MyApplication.getInstance().infoFragments[position].getLabel();
          }
  
          return tabLabel;
      }
  }
  </code></pre>
  
  <p>TabFragment class:</p>
  
  <pre><code>import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  /**
   * A fragment that launches other parts of the demo application.
   */
  public class TabFragment extends Fragment {
  
      public static final String ARG_OBJECT = "object";
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          Bundle args = getArguments();
          int position = args.getInt(ARG_OBJECT);
  
          int tabLayout = 0;
  
          if(0 &lt;= position &amp;&amp; position &lt; MyApplication.getInstance().infoFragments.length) {
              tabLayout = MyApplication.getInstance().infoFragments[position].getLayout();
          }
  
          View rootView = inflater.inflate(tabLayout, container, false);
  
          return rootView;
      }
  }
  </code></pre>
  
  <p>MyApplication class</p>
  
  <pre><code> import android.app.Application;
  
      public class MyApplication extends Application {
  
          //SIGLETON DECLARATION
  
          private static MyApplication mInstance = null;
  
          public static MyApplication getInstance() { 
              if (mInstance == null) {
                mInstance = new MyApplication();
              }
              return mInstance;
          }
  
          public static InfoFragment[] infoFragments = new InfoFragment[] {
                  new InfoFragment("Songs", R.layout.songs)
          };
  
          public static class InfoFragment {
              private String label;
              private int layout;
  
              public InfoFragment(String label, int layout) {
                  this.label = label;
                  this.layout = layout;
              }
  
              public String getLabel() {
                  return label;
              }
  
              public int getLayout() {
                  return layout;
              }
          }
  
      }
  </code></pre>