Have button action in fragment instead of main
<p>I have an Android app where i'm using tabs (with ActionBarSherlock). So my main activity creates the tabs for me and from there i load in the fragment layouts.</p>

<p>In my <code>MainActivity.java</code> i create a tab (this is just a snippet):</p>

<pre><code>mTabsAdapter = new TabsAdapter(this, mViewPager);

mTabsAdapter.addTab(
    bar.newTab().setText("Fragment 1"),
    MainMenuFragment.class, null);
</code></pre>

<p>My MainMenu.java looks like this:</p>

<pre><code>public class MainMenuFragment extends SherlockFragment
{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.mainmenu_fragment, container, false);

        return view;
    }

    public void showMainMenu(View view)
    {
        Log.e("app", "olol: button!"); // never called!!
    }
}
</code></pre>

<hr>

<p>And this is <code>mainmenu_fragment</code></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout 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:background="#000000" &gt;

    &lt;Button
        android:id="@+id/btnMenu"
        android:layout_width="170dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="41dp"
        android:text="@string/mainmenu"
        android:onClick="showMainMenu" /&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>Now all i have to do is place the method <code>showMainMenu(View view)</code> somewhere. I thought this would go in the corresponding java file (MainMenuFragment.java in my case). But it only works when i put the method in the MainAvtivity.java file.</p>

<p>That means that all my button actions from all kinds of fragment layouts will go in one (the main) java file. Why can't i simply place it inside the java file that calls the Fragment layout..??</p>
