title: create dialog box android
body: <p>I'm new at coding Android applications and I want to know how to create a dialog box. I've looked at the page on <a href="http://developer.android.com/guide/topics/ui/dialogs.html" rel="nofollow">android developers</a> but I'm not sure.</p>
  
  <p>Do I have to create an Activity or a Class with the name <code>DialogFragment</code> as in this example?</p>
  
  <pre><code>public class FireMissilesDialogFragment extends DialogFragment { ... }
  </code></pre>
  
  <p>Because I haven't created any <code>DialogFragment</code> so Eclipse doesn't know it. Maybe I have to introduce some code in an other file like an .xml or a .java?</p>
  
  <p>The point is to have a Dialog like this:</p>
  
  <pre><code>public class QuestionDialogFragment extends DialogFragment {
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          // Use the Builder class for convenient dialog construction
          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
          builder.setMessage(R.string.dialog_question)
                 .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
                         // Answering the question by yes or no or a date picker
                     }
                 })
                 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
                         // User cancelled the dialog
                     }
                 });
          // Create the AlertDialog object and return it
          return builder.create();
      }
  }
  </code></pre>