title: How can I identify the current fragment of my activity while using tabs and fragment container?
body: <p>I want to call an fragment method from my activity, describe like in this SO-question: <a href="https://stackoverflow.com/questions/11550929/call-functions-of-activities-belonging-to-a-fragment" title="FindByID">FindByID</a></p>
  
  <pre><code>TestFragment testFrag = (TestFragment) getFragmentManager().getFragmentById(R.id.testfragment);
  
  if(testFrag != null &amp;&amp; testFrag.isAdded())
      testFrag.testMethod("Test");
  </code></pre>
  
  <p>As seen they identify the fragment by ID which is set in the xml. As I only have a fragment container none of my fragment layouts have a ID.</p>
  
  <p>So my seconds thought was using the function <code>getFragmentByTag</code> `like in <a href="https://stackoverflow.com/questions/9294603/get-currently-displayed-fragment" title="Tags">Tags</a> </p>
  
  <pre><code>fragmentTransaction.replace(R.id.frameTitle, casinodetailFragment, "fragmentTag");
  </code></pre>
  
  <ul>
  <li>but as I use an action bar with tabs I don't have any tags:</li>
  </ul>
  
  <p>My activity:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragmentcontainer);
  
    // ActionBar gets initiated
    ActionBar actionbar = getActionBar();
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
    // Define Tabs
    ActionBar.Tab BasicInfoTab = actionbar.newTab().setText(
        R.string.tab_BaseInfo);
    ..
  
    // Define Fragments
    PlantBasicInfoFragment BasicInfoFragment = new PlantBasicInfoFragment();
    ..
  
    // Set TabListeners
    BasicInfoTab.setTabListener(new TabListener(BasicInfoFragment));
    ..
  
    // Add tabs to Actionbar
    actionbar.addTab(BasicInfoTab);
    ..
  
    // Icon clickable
    actionbar.setDisplayHomeAsUpEnabled(true);
  }
  </code></pre>
  
  <p>and its layout:</p>
  
  <pre><code>&lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_gravity="center"&gt;
  
        &lt;LinearLayout 
            android:orientation="horizontal"
            android:id="@+id/LabeledObjectHeaderInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            &gt;
  
  
          &lt;!-- ... --&gt;
  
     &lt;/LinearLayout &gt; 
  
  
        &lt;!-- fragment container --&gt;
     &lt;LinearLayout
            android:orientation="horizontal"
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            &gt;
     &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>One of my fragments:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
      &lt;TableLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:id="@+id/table"&gt;
  
          &lt;TableRow&gt;
            &lt;!-- ... --&gt;
          &lt;/TableRow&gt;
  
          &lt;!-- ... --&gt;
  
  
    &lt;/TableLayout&gt;
  </code></pre>
  
  <p>and finally my tab listener</p>
  
  <pre><code>public class TabListener implements ActionBar.TabListener {
  
    public Fragment fragment;
  
    public TabListener(Fragment fragment) {
      this.fragment = fragment;
    }
  
  
    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
  
    }
  
    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
  
      ft.replace(R.id.fragment_container, fragment);
    }
  
    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  
      ft.remove(fragment);
  
    }
  
  }
  </code></pre>
  
  <p>So how can I identify my current fragment?    </p>
  
  <p>Thanks in advance</p>
  
  <p>P.S. The whole tab switching works perfectly, but now I want to build an addional feature inside the activity!</p>