onClick (mis)fired for previously displayed View?
<p>I have two fragments:</p>

<ul>
<li>1st fragment consists of a large button in the middle - I set an <code>OnClickListener</code> (programmatically) for this View, which replaces the 1st fragment with the 2nd once clicked.</li>
<li>2nd fragment is an empty fragment</li>
</ul>

<p>At first, I display fragment no. 1. I then press the button and as expected, I get to see the 2nd fragment.</p>

<p>The problem: Once the 2nd fragment is displayed and I click in the middle of it - it fires the code behind the <code>OnClickListener</code> of the button in the <strong>1st fragment</strong>, even though I'm currently displaying an EMPTY FRAGMENT with no buttons at all.</p>

<p>Ideas?</p>

<p>Here's the code:</p>

<pre><code>public void onLargeButtonClick(View view){
        secondFragment fragment = new secondFragment();
        fragmentFactory.replaceFragment(fragment);
}

void replaceFragment(Fragment fragment){
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    String fragmentName = fragment.getClass().getSimpleName();
    Fragment existingFragment = fragmentManager.findFragmentByTag(fragmentName);
    if (existingFragment != null)
        fragmentManager.popBackStack(fragmentName, FragmentManager.POP_BACK_STACK_INCLUSIVE);

        FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        ft.replace(R.id.first_fragment, fragment);
        ft.addToBackStack(null);
        ft.commit();
}
</code></pre>

<p>and the main layout contains the fragment which I replace</p>

<pre><code>   &lt;fragment
            android:name="com.app.firstfragment"
            android:id="@+id/first_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            &gt;
    &lt;/fragment&gt;
</code></pre>
