title: How do you connect a CustomListAdapter to a List Fragment in the Activity?
body: <p>The context is:</p>
  
  <ol>
  <li>I have an activity consisting of a fragment where there is a form to enter a date and a flight number. There are no other fragments there.</li>
  <li>On click of a button, a request is made to a webservice.</li>
  <li>A <code>List</code> of Flight Objects is returned from the webservice.</li>
  <li>A custom <code>ArrayAdapter</code> is created for each row in the listFragment.</li>
  <li>Show the results in a ListFragment in the same Activity on the frontend.</li>
  </ol>
  
  <p><strong>FlightResultAdapter.java:</strong></p>
  
  <pre><code>public class FlightResultAdapter extends ArrayAdapter&lt;Flight&gt;{
      public FlightResultAdapter(Context context, List&lt;Flight&gt; flights) {
          super(context, R.layout.item_flight, flights);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          Flight flight = getItem(position);
  
          if (convertView == null){
              convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_flight, parent, false);
          }
  //Set the content of the custom row layout
          TextView tvFlightNum = (TextView) convertView.findViewById(R.id.tvFlightNum);
          tvFlightNum.setText(flight.getNumber());
  
          return convertView;
      }
  }
  </code></pre>
  
  <p><strong>Note: ListFragment has a default layout that consists of a single list view.</strong> <a href="http://developer.android.com/reference/android/app/ListFragment.html" rel="nofollow">Source</a></p>
  
  <p>So I do not need a layout file for the list.</p>
  
  <p><strong>MyActivity.java:</strong> A list of objects (<code>flightList.getFlight</code>) is used to create the <code>CustomListAdapter</code>. This code is inside a function that is triggered on an <code>OnClick</code>.</p>
  
  <pre><code>FlightResultAdapter adapter = 
  new FlightResultAdapter(getApplicationContext(), flightList.getFlight());
  </code></pre>
  
  <p><strong>FlightFragment.java</strong></p>
  
  <pre><code>public class FlightFragment extends ListFragment {
  
      private List&lt;Flight&gt; flight_items;
  
      public FlightFragment() {
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          flight_items = new ArrayList&lt;Flight&gt;();
  
          //Initialise the list adapter and set
          FlightResultAdapter adapter = new FlightResultAdapter(getActivity(), flight_items);
          setListAdapter(adapter);
      }
  
      @Override
      public void onListItemClick(ListView l, View v, int position, long id) {
          super.onListItemClick(l, v, position, id);
  
          Flight flight = flight_items.get(position);
  
          Toast.makeText(getActivity(), flight.getNumber(), Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p>So what I'm not getting is how to Show the <code>FlightFragment</code> on <code>MyActivity</code>.
  Furthermore how to connect it so results are displayed: I think <code>setListAdapter</code> is used?</p>
  
  <p><strong>Update: Connecting the Fragment to the Activity</strong>
   1. Add a FrameLayout to the activity layout, or other fragment layout</p>
  
  <pre><code>&lt;FrameLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/fragment_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>2. Use the FragmentManager to call the Fragment programmatically:</p>
  
  <pre><code>//Create the adapter here
          FlightResultAdapter adapter = new FlightResultAdapter(getApplicationContext(), flightList.getFlight());
  
          //Get the Fragment here and set the ListAdapter
          FlightFragment ff = new FlightFragment();
          // In case this activity was started with special instructions from an
          // Intent, pass the Intent's extras to the fragment as arguments
          ff.setArguments(getIntent().getExtras());
  
          ff.setListAdapter(adapter);
  
          if (findViewById(R.id.fragment_container) != null) {
  
              //Send the Data to the fragment - Need Help Here
              Bundle bundle = new Bundle();
  
              //Show the Fragment
              FragmentManager fragmentManager = getFragmentManager();
              FragmentTransaction fragmentTransaction =
                      fragmentManager.beginTransaction();
              fragmentTransaction.add(R.id.fragment_container, ff);
              fragmentTransaction.commit();
          }
  </code></pre>
  
  <p>So the Fragment's <code>OnCreate</code> Method is being called, but the list is empty because I am not passing the <code>Flight</code> Object to the Fragment. How can I do this?</p>