get the FragmentManager from within a Fragment (support.v4) : <p>Be aware, I am using the <code>android.support.v4.app.FragmentManager</code>. I have searched all over the internet, I have found many similar questions, but they are all referring to <code>android.app.FragmentManager</code> and none of the solutions work with support.v4 FragmentManager.</p>

<pre><code>import android.support.v4.app.FragmentManager;
</code></pre>

<p>I am using Fragments instead of Activities for navigation purposes. Inside my MainActivity I have a NavigationDrawer which is used to select a Fragment to be displayed using the following method:</p>

<pre><code>public boolean onNavigationSelected(MenuItem item) {

    FragmentManager fragManager = getSupportFragmentManager();

    if(item.getItemId() == R.id.fragment_one) {
        fragManager.beginTransaction().replace(R.id.content, new FragmentOne()).commit()
    }
    if(item.getItemId() == R.id.fragment_two) {
        fragManager.beginTransaction().replace(R.id.content, new FragmentTwo()).commit()
    }

}
</code></pre>

<p>This works fine when a user navigates using the NavigationDrawer, but there are Buttons inside the Fragment which are used for navigation too, however the <code>getSupportFragmentManager()</code> method cannot be called from within a Fragment.</p>

<p>FragmentOne:</p>

<pre><code>public class FragmentOne extends Fragment {

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        // Inflate the layout for the Fragment
        fragment = inflater.inflate(R.layout.fragment_one_layout, container, false);

        // Do some stuff to the fragment before returning it

        Button button = (Button) findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                // This does not work
------------&gt;   FragmentManager fragManager = getSupportFragmentManager();
                fragManager.beginTransaction().replace(R.id.content, new FragmentTwo()).commit();
            }
        });

        return fragment;
    }
}
</code></pre>
