title: Automatically disable/enable a listener based on its Fragment visibility
body: <p>In an Android app, I have <strong>two fragments</strong>:</p>
  
  <ol>
  <li><p>a fragment with a <strong>ListView</strong> of items</p></li>
  <li><p>a fragment with an <strong>ImageView</strong></p></li>
  </ol>
  
  <p>Through callback onListItemSelected, when a user clicks on a ListView item, MainActivity pushes the ImageView on the stack and the fragment with the image appears on the screen. At this point I would expect that, since the ListView fragment is no longer visible, any events associated to this fragment are no longer fired. This is not the case. If I touch the ImageView, the listeners of the ListView items still fire.</p>
  
  <p>Two questions:</p>
  
  <ol>
  <li><p>Is there a way to <strong>automatically</strong> enable/disable listeners based on their Fragment visibility?</p></li>
  <li><p>If not, I guess the way to go would be to disable the ListView fragment view and then re-enable it when the backButton is pressed. How can I capture the backButton event in the MainActivity to re-enable a previously disabled view?</p></li>
  </ol>
  
  <blockquote>
    <p>public class MainActivity extends FragmentActivity implements
     ListViewFragment.Callbacks {</p>
    
    <p>[...]</p>
  
  <pre><code>       public void onListItemSelected(String str) {
  
  
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();       
  
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.replace(R.id.listView, f);
            fragmentTransaction.commit();
  
            // disable listView 
            //View lw = getSupportFragmentManager().findFragmentById(R.id.listView).getView().findViewById(R.id.my_listView);
            //lw.setEnabled(false);
  
         }
  </code></pre>
  </blockquote>