title: Two Fragments One Screen
body: <p>I have implemented an <code>Activity</code> that hosts two fragments. I have one fragment on the left and one on the right. The fragment on the left is a list of items to click. When you click on it inflates a new fragment on the right.</p>
  
  <p>One item on the left list is supposed to inflate a different list on the right. I have it working good except when you click that item it inflates the list to cover the entire screen. And I only want it to cover the space on the right side of the screen.</p>
  
  <p>Is there a way I can keep the fragment from covering the entire screen? All the others stay on the right side of the screen, its just this one that doesn't. But this is the only one trying to inflate a <code>ListView</code> on the right side.</p>
  
  <p>Here are the relevant methods of the <code>ListFragemnt</code> that is supposed to be on the right inflated on the right side:</p>
  
  <pre><code>public void onActivityCreated(Bundle inState) {
      super.onActivityCreated(inState);
      //setContentView(R.layout.results_list_activity);
      //mIntent = getIntent();
      mActivity = getActivity();
      mArrayListRecipe = generateList();
  
      ListView listView = (ListView) mActivity.findViewById(android.R.id.list);
      ArrayAdapter&lt;Recipe&gt; adapter = new ArrayAdapter&lt;Recipe&gt;(mActivity,
              android.R.layout.simple_list_item_1, mArrayListRecipe);
  
      listView.setAdapter(adapter);
      //listView.setOnItemClickListener((OnItemClickListener) this);
  }
  
  public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.results_list_activity, container, false);
      return layout;
  }
  </code></pre>
  
  <p>And here is the XML layout that is inflated called results_list_activity.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
  &lt;ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list"
            android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here is the layout that contains the frame that I want this <code>ListView</code> placed in <strong>main_activity.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_layout_land"
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:orientation="horizontal" android:layout_alignParentBottom="true"&gt;
  
  &lt;!-- Left side fragment --&gt;
  &lt;fragment class="com.jasoncrosby.app.recipeorganizer.MainFragment" android:id="@+id/left_fragment"
                android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/&gt;
  
  &lt;!-- Right side fragment --&gt;
  &lt;FrameLayout android:id="@+id/right_fragment" android:layout_width="0dp" android:layout_height="match_parent"
                   android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>The activity that loads the fragment is simple and only consists of a call to:</p>
  
  <pre><code>setContentView(R.layout.main_activity);
  </code></pre>
  
  <p>Here is <strong>MainFragment.java</strong>:</p>
  
  <pre><code>public class MainFragment extends ListFragment {
  
  //*******
  // Fields
  //*******
  
      /** Indicated weather there is enough room on the screen to use 2 panes. */
      private boolean mDualPane;
  
      /** Indicates which item in the main list was clicked. */
      private int mCurCheckPosition = 0;
  
      /** The name of the save button. */
      private String mStringSaveItemName;
  
      /** The name of the search button. */
      private String mStringSearchItemName;
  
      /** The name of the browse button. */
      private String mStringBrowseItemName;
  
      /** The name of the random button. */
      private String mStringRandomItemName;
  
      /** The {@code Activity} associated with this {@code Fragment}. */
      private Activity mActivity;
  
  //*************
  // Constructors
  //*************
  
  /**
   * This constructor is only provided to avoid a compiler warning. It should not be used to crate a new
   * {@code MainFragment} object.
   */
  public MainFragment(){}
  
  /**
   * Used to create a new {@code MainFragment} object with the id.
   * 
   * @param id
   */
  //public MainFragment(int id) {
      //mIntFragmentId = id;
      //mContext = context;
  //}
  
  //*******************
  // Overridden methods
  //*******************
  
  @Override
  public void onActivityCreated(Bundle savedState) {
      super.onActivityCreated(savedState);
  
      mActivity = getActivity();
  
      mStringSaveItemName = mActivity.getString(R.string.save_button);
      mStringSearchItemName = mActivity.getString(R.string.search_button);
      mStringBrowseItemName = mActivity.getString(R.string.browse_button);
      mStringRandomItemName = mActivity.getString(R.string.random_button);
  
      // Populate list with our static array of titles.
      setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_list_item_1,
              new String[] {mStringSaveItemName, mStringSearchItemName, mStringBrowseItemName,
              mStringRandomItemName}));
  
      // Check to see if we have a frame in which to embed the details
      // fragment directly in the containing UI.
      View detailsFrame = mActivity.findViewById(R.id.right_fragment);
      mDualPane = detailsFrame != null &amp;&amp; detailsFrame.getVisibility() == View.VISIBLE;
  
      if (mDualPane) {
          // In dual-pane mode, list view highlights selected item.
          getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
          // Make sure our UI is in the correct state.
          showDetails(mCurCheckPosition);
      }
  }
  
  @Override
  public void onListItemClick(ListView l, View v, int pos, long id) {
      showDetails(pos);
  }
  
  //****************
  // Private methods
  //****************
  
  private void showDetails(int index) {
      mCurCheckPosition = index;
  
      if (mDualPane) {
  
          switch (mCurCheckPosition) {
              case 0  : inflateFirstUi(); break;
              case 1  : inflateSecondUi(); break;
              case 2  : inflateThirdUi(); break;
              case 3  : inflateFourthUi(); break;
              default : inflateFirstUi(); break;
          }
  
      } else {
          // Otherwise we need to launch a new activity to display
          // the dialog fragment with selected text.
          Intent intent = new Intent();
          //intent.setClass(getActivity(), DetailsActivity.class);
          intent.putExtra("index", index);
          startActivity(intent);
      }
  }
  
  private void inflateFirstUi() {
      SaveFragment details = new SaveFragment();
  
      FragmentTransaction ft = getFragmentManager().beginTransaction();
      ft.replace(R.id.right_fragment, details);
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      ft.commit();
  }
  
  private void inflateSecondUi() {
      SearchFragment details = new SearchFragment();
  
      FragmentTransaction ft = getFragmentManager().beginTransaction();
      ft.replace(R.id.right_fragment, details);
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      ft.commit();
  }
  
  private void inflateThirdUi() {
      ResultsListFragment details = new ResultsListFragment(Constants.BROWSE_REQUEST);
  
      FragmentTransaction ft = getFragmentManager().beginTransaction();
      ft.replace(R.id.right_fragment, details);
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      ft.commit();
  }
  
  private void inflateFourthUi() {
      ResultsListFragment details = new ResultsListFragment(Constants.RANDOM_REQUEST);
  
      FragmentTransaction ft = getFragmentManager().beginTransaction();
      ft.replace(R.id.right_fragment, details);
      ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      ft.commit();
  }
  }
  </code></pre>
  
  <p>The problem is in the <code>showDetails()</code> method in the switch statement. Case 0 and case 1 work just fine and load in the pane I have on the right side of the screen. Case 3 is where I am running into this problem. It loads the UI but its covering the entire screen and not confined to the right side in the pane.</p>