title: FragmentManager multiple on-screen fragments?
body: <p>On Android 3.0 and above, the android team is driving hard that you should use fragments over activities. And I see this being useful, but I want to be able to handle click events in my app. I'm using a list fragment on the right side of my app, so doing an onclick (or any click listeners) happens in the activity that hosts the fragment. So I had to move from putting a  item in XML to using the fragment manager.</p>
  
  <p>In the design documents they show this picture:<img src="https://i.stack.imgur.com/GjoVt.png" alt="Misleading Photo"></p>
  
  <p><a href="http://developer.android.com/training/basics/fragments/fragment-ui.html" rel="nofollow noreferrer">http://developer.android.com/training/basics/fragments/fragment-ui.html</a></p>
  
  <p>What I want is the Fragment A/B tablet UI. However, nowhere in this page does it actually give you an example of doing this - it seems that fragment manager only works with ONE fragment at a time - which is entirely opposite of what the picture portrays. Which makes me think it uses  in XML... but then how would I get an onclick? These documents don't make a lot of sense to me. It shows one thing and then says something else. What if I wanted to remove fragment A on the tablet? Add fragment C that doesn't yet exist? Is that even possible if you tried to use Fragment Manager????</p>
  
  <p>I guess I don't get if Fragment manager uses more than 1 fragment, and if it does, how am I supposed to use this to get an item in the picture like the tablet - the left (A) being a listview, and the right (B) being whatever. Without an ID of the fragment I don't how to access it.</p>
  
  <p>Not sure if this is relevant but here is some of my code:</p>
  
  <p>Adds a fragment to the single framelayout I made like in the guide</p>
  
  <pre><code>//Activity              
  FragLaunch launchPane = new FragLaunch();
                  // In case this activity was started with special instructions from an Intent,
                  // pass the Intent's extras to the fragment as arguments
                  // firstFragment.setArguments(getIntent().getExtras());
  
                  // Add the fragment to the 'fragment_container' FrameLayout
                  getFragmentManager().beginTransaction()
                          .add(R.id.launch_frag_container, launchPane).commit();
              }
  </code></pre>
  
  <p>Also, in portrait mode of 7" tablets, I want it to use a viewpager that is swipeable. It worked like a charm when I designed it in XML but now that I have to access the listfragment it doesn't work (no way to access since I can't have two fragments)</p>
  
  <p>XML of FragLaunch's content view:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingLeft="16dp"
      android:paddingRight="16dp"
      android:gravity="center_vertical"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/initial_directions"
          style="@style/textScalar.Roboto.Light"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:text="@string/initial_directions"
          android:layout_marginBottom="30dp"
          tools:context=".Launch" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I want to have this one appear as Fragment A in the photo:
  FragHistory.java/xml for fragment:</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="vertical" &gt;
  
      &lt;Button
          android:id="@+id/spamhistory"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Spam History" /&gt;
  
      &lt;ListView
          android:id="@android:id/list"
          android:layout_width="match_parent"
          android:layout_height="0dip"
          android:layout_weight="1"
          android:drawSelectorOnTop="false" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Does anyone have any insight on this?</p>