title: Show dialog from fragment?
body: <p>I have some fragments that need to show a regular dialog. On these dialogs the user can choose a yes/no answer, and then the fragment should behave accordingly.</p>
  
  <p>Now, the <code>Fragment</code> class doesn't have an <code>onCreateDialog()</code> method to override, so I guess I have to implement the dialogs outside, in the containing <code>Activity</code>. It's ok, but then the <code>Activity</code> needs to report back the chosen answer somehow to the fragment. I could of course use a callback pattern here, so the fragment registers itself at the <code>Activity</code> with a listener class, and the Activity would report back the answer thru that, or something like that.</p>
  
  <p>But this seems to be quite a big mess for a simple task as displaying a "simple" yes-no dialog in a fragment. Also, this way my <code>Fragment</code> would be less self-contained.</p>
  
  <p>Is there some cleaner way to do this?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The answer to this question doesn't really explain in detail how one should use DialogFragments to display dialogs from Fragments. So AFAIK, the way to go is:</p>
  
  <ol>
  <li>Display a Fragment.</li>
  <li>When needed, instantiate a DialogFragment.</li>
  <li>Set the original Fragment as the target of this DialogFragment, with <code>.setTargetFragment()</code>.</li>
  <li>Show the DialogFragment with .show() from the original Fragment.</li>
  <li>When the user chooses some option on this DialogFragment, notify the original Fragment about this selection (e.g. the user clicked 'yes'), you can get the reference of the original Fragment with .getTarget().</li>
  <li>Dismiss the DialogFragment.</li>
  </ol>