title: Adding ListFragment dynamically on android
body: <p>I am trying to make an android layout where I have ListFragment on the left of the screen that contains menu entries and then an area to the right of the ListFragment where I can programmatically load in different fragments based on the entry selected on the left. So I started off by making an xml layout file that has a horizontal linear layout which contains two frame layouts. My thought was that I could load my fragments into the frame layouts.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="0dp"
      android:layout_height="match_parent"&gt;
  
      &lt;FrameLayout 
          android:id="@+id/fragment_container_left"
          android:layout_width="match_parent"
          android:layout_height="match_parent" 
          android:layout_weight="30"/&gt;
  
  
      &lt;FrameLayout 
          android:id="@+id/fragment_container_right"
          android:layout_width="match_parent"
          android:layout_height="match_parent" 
          android:layout_weight="70"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Then in my MainViewActivity class in the onCreate method I add a list fragment to the left container, and a list fragment to the right container.</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.menu_items);
  
      if(findViewById(R.id.fragment_container_left) != null) {
          if(savedInstanceState == null){
              MenuListFragment menuListFragment = new MenuListFragment();
              FragmentManager fm = getFragmentManager();
              FragmentTransaction ft = fm.beginTransaction();
              ft.add(R.id.fragment_container_left, menuListFragment);
              ft.commit();
          }
      } 
  
      if(findViewById(R.id.fragment_container_right) != null) {
          if(savedInstanceState == null){
              MoveListFragment moveListFragment = new MoveListFragment();
              FragmentManager fm = getFragmentManager();
              FragmentTransaction ft = fm.beginTransaction();
              ft.add(R.id.fragment_container_right, moveListFragment);
              ft.commit();
          }
      }
  }
  </code></pre>
  
  <p>So then the onCreate method of the MenuListFragment is:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setListAdapter(ArrayAdapter.createFromResource(getActivity().getApplicationContext(),
              R.array.menu_items, R.layout.main_menu_item));
  }
  </code></pre>
  
  <p>And then the onCreate method of the MoveListFragment is:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      String[] items = { "move 1", "move 2", "move 3", "move 4" };
      setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), R.layout.move_list_items, items));
  }
  </code></pre>
  
  <p>and here is the main_menu_item xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="24sp"
      android:padding="6dp" 
      android:id="@+id/main_menu_item"/&gt;
  </code></pre>
  
  <p>and move_list_items xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="24sp"
      android:padding="6dp" 
      android:id="@+id/move_list_item"/&gt;
  </code></pre>
  
  <p>When I run this code, I do not get any errors of any kind, but nothing but a white background shows up on the screen. I do not understand what I am doing wrong.</p>