title: Honeycomb: Several fragments in each Tab in Action Bar
body: <p>I'm quite new to android and java and I want to implement the following functions in action Bar:</p>
  
  <p>TAB 1 : Displays ListFragment A and Listfragment B</p>
  
  <p>TAB 2 : Displays ListFragment C and Listfragment D</p>
  
  <p>I already made the code to display a view with ListFragment A and Listfragment B but without action Bar. I'm trying to integrate action bar with tabs and now it is not working and I'm not able to figure out what is wrong or find a post with a solution.
  I'm using an activity for each Fragment. </p>
  
  <p>At the moment, I can display one fragment in each tab with the action bar :</p>
  
  <ul>
  <li><p>fragment A appears when I click in Tab 1</p></li>
  <li><p>Fragment C appears when I click in Tab 2</p></li>
  </ul>
  
  <p>My Problem is:
  When I click on an item in Fragment A, Fragment B appears in a new View ( = without either action bar nor fragment A)</p>
  
  <p>=> How should I do to display in the same view : Action Bar, Fragment A and Fragment B?</p>
  
  <p>=> I don't understand really how I should configure action bar to appear on top of each view. Is it done in a separate xml? How is it configured? Should we call action bar on top of each activity?</p>
  
  <p>=> I don't understand really why I need 4 levels of xml to display these fragments. </p>
  
  <p>For my code, I used several tutorials from following links but now I'm not able to find an answer:</p>
  
  <p><a href="http://mobile.tutsplus.com/tutorials/android/android-sdk_fragments/" rel="nofollow">http://mobile.tutsplus.com/tutorials/android/android-sdk_fragments/</a></p>
  
  <p>Adding tabs from <a href="http://www.devdiv.com/android/docs/guide/topics/ui/actionbar.html" rel="nofollow">http://www.devdiv.com/android/docs/guide/topics/ui/actionbar.html</a></p>
  
  <p>dgn2_action_bar.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:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;LinearLayout android:layout_height="wrap_content"
          android:layout_width="match_parent"
          android:id="@+id/fragment_place"&gt;   
  &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>dgn2_synth_entry.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="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="horizontal" &gt;   
  
          &lt;fragment
              android:id="@+id/listFragment"
              android:layout_width="150dip"
              android:layout_height="match_parent"
              android:layout_weight="1"
              android:layout_marginTop="?android:attr/actionBarSize"
              class="com.android.FragmentA" &gt;      
          &lt;/fragment&gt;
  
          &lt;fragment
              android:id="@+id/detailSynthFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_weight="2"
              class="com.android.FragmentB" &gt;
              &lt;!-- Preview: layout=@layout/details --&gt;
          &lt;/fragment&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>dgn2_synth_detail_layout.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="vertical" &gt;
  
          &lt;fragment
              android:id="@+id/detailSynthFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              class="com.android.FragmentB" /&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>dgn2_details.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="vertical" &gt;
  
            &lt;ListView  
            android:id="@+id/resultFragmentView"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:divider="#ffffff" 
            /&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Dgn2EntryActivity.java</p>
  
  <pre><code>public class Dgn2EntryActivity extends Activity implements      Dgn2SynthListFragment.OnSheetSelectedListener
  {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.dgn2_action_bar);
  
      /* Setup Action Bar for tabs */
      ActionBar mActionBar = getActionBar();
      mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
      /* add a new tab and set its title text */
      ActionBar.Tab tabSynthesis = mActionBar.newTab().setText(R.string.sSynthesisTab);
      ActionBar.Tab tabParameter = mActionBar.newTab().setText(R.string.sParameterTab);
  
      /* instantiate fragment for the tab */
      ListFragment mSynthesisFragment = new FragmentA();
      ListFragment mParamFragment = new FragmentC();    
  
      /* Set Listener on Tab Action */
      tabSynthesis.setTabListener(new MyTabsListener(mSynthesisFragment));
      tabParameter.setTabListener(new MyTabsListener(mParamFragment));
  
      /* Add Tab in Action Bar */
      mActionBar.addTab(tabSynthesis);
      mActionBar.addTab(tabParameter);
  }
  
  public void onSheetSelected(String sheetID, FragmentB viewer)
  {     
      if (viewer == null || !viewer.isInLayout()) 
      {   
          /*initialise Fragment call */            
          Intent intent = new Intent(getApplicationContext(),FragmentBActivity.class);
          intent.putExtra("value", sheetID);
          startActivity(intent);
      } 
      else 
      {
          /* Update Fragment content after a click */
          viewer.updateSheet(sheetID);
      }    
  } 
  
  protected class MyTabsListener implements ActionBar.TabListener
  {
      private ListFragment mFragment;
  
      public MyTabsListener(ListFragment mFragment)
      {
          this.mFragment = mFragment;
      }
  
  
      public void onTabSelected(Tab paramTab,
              FragmentTransaction paramFragment) 
      {
            paramFragment.add(R.id.fragment_place, mFragment, null);
      }
  
      public void onTabUnselected(Tab paramTab,
              FragmentTransaction paramFragment) 
      {
          paramFragment.remove(mFragment);        
      }
      public void onTabReselected(Tab paramTab,
              FragmentTransaction paramFragment) 
      {  
      }               
  }
  }
  </code></pre>
  
  <p>FragmentBActivity.java</p>
  
  <pre><code>public class FragmentBActivity extends Activity 
  {    
  @Override
  protected void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.dgn2_synth_detail_layout);
  
      /* get Sheet Label */
      Bundle extras = getIntent().getExtras();
      if (extras != null) 
      {
          String sheetLabel = extras.getString("value");
          FragmentB viewer = (FragmentB) getFragmentManager()
                  .findFragmentById(R.id.detailSynthFragment);
          /*Update Fragment Viewer view content*/
          viewer.updateSheet(sheetLabel);
      } 
  }    
  }
  </code></pre>
  
  <p>FragmentA.java</p>
  
  <pre><code>public class FragmentA extends ListFragment 
  {   
  private OnSheetSelectedListener sheetSelectedListener;
  
   public interface OnSheetSelectedListener 
  {
      public void onSheetSelected(String sheetID, FragmentB viewer);
  } 
  
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) 
  {
      super.onActivityCreated(savedInstanceState);
      String[] values = new String[] { GLOBAL_SYNTHESIS_LABEL, SYNTHESIS1_LABEL};
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(),
              android.R.layout.simple_list_item_1, values);
      setListAdapter(adapter);
  }
  
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) 
  {       
      String item = (String) getListAdapter().getItem(position);
      FragmentB viewer = (FragmentB) getFragmentManager().findFragmentById(R.id.detailFragment);
      sheetSelectedListener.onSheetSelected(item, viewer);
  }
  }
  </code></pre>
  
  <p>FragmentB.java</p>
  
  <pre><code>public class FragmentB extends ListFragment 
  {
  Context mContext;
  Dgn1DataListClass allResults = new Dgn1DataListClass(); 
  String[] vIhmDgnVarNameList;
  Dgn1ResultCouple[] results;  
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) 
  {
      super.onActivityCreated(savedInstanceState);
      updateSheet(GLOBAL_SYNTHESIS_LABEL);
  }
  
  public void updateSheet(String sheetLabel) 
  {
      mContext = getActivity();
      ListView resultListView =(ListView)getView().findViewById(R.id.resultFragmentView);
  
      if (sheetLabel == GLOBAL_SYNTHESIS_LABEL)
      {
          /* Displays A list in 2 columns */
          vIhmDgnVarNameList = getResources().getStringArray(R.array.ihm_dgn_row1_array);
          results = allResults.fillResults(vIhmDgnVarNameList);
          ListItemAdapter2 mcqListAdapter = new ListItemAdapter2(mContext,R.layout.ihm_dgn_row_data,results);
          setListAdapter(mcqListAdapter);
      }
      else if (sheetLabel == SYNTHESIS1_LABEL)
      {
              /* TODO */
      }
  }
  
  public class ListItemAdapter2 extends ArrayAdapter&lt;Dgn1ResultCouple&gt;
  {
      /* Lot Of Code working*/  
  }
  }
  </code></pre>
  
  <p>Thanks for your help</p>