title: Use of setListAdapter
body: <p>In my application 4 fragments are attached to one activity class. In my activity class i have set the root content view using  this</p>
  
  <pre><code>setContentView(R.layout.fragment_pager);
  </code></pre>
  
  <p>my four fragments are in seperate java files.</p>
  
  <p>In one of my fragment i am displaying a list of contact for this i used </p>
  
  <pre><code>mAdapter = new SimpleCursorAdapter(getActivity(),
                  android.R.layout.simple_list_item_1, null,
                  new String[] {ContactsContract.Contacts.DISPLAY_NAME},
                  new int[] { android.R.id.text1}, 0);
  
  
  setListAdapter(mAdapter);
  setListShown(true);
  </code></pre>
  
  <p>I want to know that what is the use of setListAdapter in my case and where it put list of content given by SimpleCursorAdapter class? and how can i set the title of my fragment.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:drawable/gallery_thumb"&gt;
  
      &lt;TextView android:id="@+id/text"
          android:layout_width="match_parent" android:layout_height="wrap_content"
          android:gravity="center_vertical|center_horizontal"
          android:textAppearance="?android:attr/textAppearanceMedium"
          android:text="@string/hello_world"/&gt;
  
      &lt;!-- The frame layout is here since we will be showing either
      the empty view or the list view.  --&gt;
      &lt;FrameLayout
          android:layout_width="match_parent"
          android:layout_height="0dip"
          android:layout_weight="1" &gt;
          &lt;!-- Here is the list. Since we are using a ListActivity, we
               have to call it "@android:id/list" so ListActivity will
               find it --&gt;
          &lt;ListView android:id="@android:id/list"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:drawSelectorOnTop="false"/&gt;
  
          &lt;!-- Here is the view to show if the list is emtpy --&gt;
          &lt;TextView android:id="@android:id/empty"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:text="No items."/&gt;
  
      &lt;/FrameLayout&gt;
  
  &lt;/LinearLayout&gt;
  
  
  
   @Override
      public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);  
  
           mAdapter = new SimpleCursorAdapter(getActivity(),
                  android.R.layout.simple_list_item_1, null,
                   new String[] {ContactsContract.Contacts.DISPLAY_NAME},
                   new int[] { android.R.id.text1}, 0);
           //setListAdapter(mAdapter);
          // setListShown(true);
          // getLoaderManager().initLoader(0, null, this);
      }    
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
          View tv = v.findViewById(R.id.text);
          ((TextView)tv).setText("Contacts");
  
          return v;
      }
  </code></pre>
  
  <p>My Cursor display data when i use this method and removes two methods onCreate and onCreateView</p>
  
  <pre><code>@Override 
      public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
  
         mAdapter = new SimpleCursorAdapter(getActivity(),
                  android.R.layout.simple_list_item_1, null,
                  new String[] {ContactsContract.Contacts.DISPLAY_NAME},
                  new int[] { android.R.id.text1}, 0);
         setListAdapter(mAdapter); 
         setListShown(true);
         getLoaderManager().initLoader(0, null, this);
  
      }
  </code></pre>
  
  <p>but when i use those three methods together then my application stops unexpectedly. What can be the error when i use these three method together?</p>
  
  <pre><code>package com.keepintouch.android;
  
  import android.os.Bundle;
  
  import android.content.Context;
  import android.database.Cursor;
  import android.net.Uri;
  
  import android.provider.ContactsContract;
  
  import android.support.v4.app.Fragment;
  import android.support.v4.app.LoaderManager;
  import android.support.v4.content.CursorLoader;
  import android.support.v4.content.Loader;
  
  import android.support.v4.widget.SimpleCursorAdapter;
  import android.util.Log;
  
  import android.view.View;
  
  
  import android.widget.ListView;
  
  
  import com.actionbarsherlock.app.SherlockListFragment;
  
  
  public class ContactsFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks&lt;Cursor&gt;{
  
       // This is the Adapter being used to display the list's data.
      SimpleCursorAdapter mAdapter;
  
      // If non-null, this is the current filter the user has provided.
      String mCurFilter;  
      View lv;
  
      // These are the Contacts rows that we will retrieve.
      static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
          ContactsContract.Contacts._ID,
          ContactsContract.Contacts.DISPLAY_NAME,
      };
  
      @Override
      public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);  
  
      }    
  
  
  
  
      public static Fragment newInstance(Context context){
          ContactsFragment contactFragment = new ContactsFragment();
          return contactFragment;
      }
  
  
      @Override 
      public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
  
         mAdapter = new SimpleCursorAdapter(getActivity(),
                  android.R.layout.simple_list_item_1, null,
                  new String[] {ContactsContract.Contacts.DISPLAY_NAME},
                  new int[] { android.R.id.text1}, 0);
  
         setListAdapter(mAdapter); 
         setListShown(true);
         getLoaderManager().initLoader(0, null, this);
  
      }
  
  
  
      @Override 
      public void onListItemClick(ListView l, View v, int position, long id) {
          // Insert desired behavior here.
          Log.i("FragmentComplexList", "Item clicked: " + id);
      }
  
  
  
      public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) {
           // This is called when a new Loader needs to be created.  This
          // sample only has one Loader, so we don't care about the ID.
          // First, pick the base URI to use depending on whether we are
          // currently filtering.
          Uri baseUri;
          if (mCurFilter != null) {
              baseUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI,
                        Uri.encode(mCurFilter));
          } else {
              baseUri = ContactsContract.Contacts.CONTENT_URI;
          }
  
          // Now create and return a CursorLoader that will take care of
          // creating a Cursor for the data being displayed.
          String select = "((" + ContactsContract.Contacts.DISPLAY_NAME + " NOTNULL) AND ("
                  + ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1) AND ("
                  + ContactsContract.Contacts.DISPLAY_NAME + " != '' ))";
          return new CursorLoader(getActivity(), baseUri,
                  CONTACTS_SUMMARY_PROJECTION, select, null,
                  ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
      }
  
      public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) {
          // Swap the new cursor in.  (The framework will take care of closing the
          // old cursor once we return.)
          mAdapter.swapCursor(data);
  
          // The list should now be shown.
          if (isResumed()) {
              setListShown(true);
          } else {
              setListShownNoAnimation(true);
          }
      }
  
      public void onLoaderReset(Loader&lt;Cursor&gt; loader) {
          // This is called when the last Cursor provided to onLoadFinished()
          // above is about to be closed.  We need to make sure we are no
          // longer using it.
          mAdapter.swapCursor(null);
      }
  
  
  
  }
  </code></pre>