title: Is it possible to get a reference to an Android Dialog from one of its children?
body: <p>I'm using a FragmentActivity with a FragmentStatePagerAdapter. In my fragments, I set click listeners on some views that respond by showing a Dialog. The Dialog layout is supplied via an XML layout resource, and some buttons in this layout use the onClick property to fire off a method in the FragmentActivity. And that works fine, the method gets called correctly when the buttons are clicked.  </p>
  
  <p>But I'd like to know how to get hold of a reference to the Dialog when the onClick method is called. All I have is the view (button) that was clicked, which is a child of the Dialog's layout. I actually just want to dismiss the dialog. And I'd really prefer not to have to make the Dialog some sort of global, static singleton or whatever, there must be a cleaner way. I'll try to illustrate it with some code:</p>
  
  <pre><code>public class MyFragment extends Fragment {
      ...
      ...
      @Override
      public View onCreateView(...) {
          ...
          dialogTrigger.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View src) {
                  MyDialog dialog = new MyDialog(src.getContext());
                  dialog.show();
              }
          });
      ...
  }
  
  public class MyActivity extends FragmentActivity {
      ...
      public void doIt(View src) {
          // dialog ref ???
      }
      ...
  }
  </code></pre>
  
  <p>...and the Dialog layout XML:</p>
  
  <pre><code>&lt;GridLayout ...&gt;
  
      &lt;Button
          ... 
          android:onClick="doIt" /&gt;
  ...
  etc.
  </code></pre>