title: How to use Dialog Fragment? (showDialog deprecated) Android
body: <p>I understand that there is this documentation</p>
  
  <p><a href="http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog">http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog</a></p>
  
  <p>but as a new Android/Java learner it is not easy to understand the amount of code involved from writing a simple alert dialog that pops up with 2 options (yes/no) message.</p>
  
  <p>Here is the code I currently have in my MainActivity file:</p>
  
  <pre><code>final private int RESET_DIALOG = 0;
  
      private OnClickListener resetButtonListener = new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              showDialog(RESET_DIALOG);
  
          }
      };
  
      protected android.app.Dialog onCreateDialog(int id) {
          switch(id) {
          case RESET_DIALOG: 
              AlertDialog.Builder builder = new Builder(this);
              return builder
                      .setMessage("Are you sure you want to reset the count?")
                      .setNegativeButton("No", new DialogInterface.OnClickListener() {    
  
                          @Override
                          public void onClick(DialogInterface arg0, int arg1) {
                              Toast.makeText(MainActivity.this, "Did not reset!", 5).show();
  
                          }
                      })
  
                      .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  
  
                          @Override
                          public void onClick(DialogInterface arg0, int arg1) {
                              Toast.makeText(MainActivity.this, "Did Reset!", 5).show();
  
                          }
                      })
                      .create();
          }
          return null;
      };
  </code></pre>
  
  <p>This is my attempt to following the instructions on the android site: Main Activity file:</p>
  
  <pre><code>final private int RESET_DIALOG = 0;
  
      private OnClickListener resetButtonListener = new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(MainActivity.this, MainDialog.class);
              startActivity(intent);
  
          }
      };
  
      protected android.app.Dialog onCreateDialog(int id) {
          switch(id) {
          case RESET_DIALOG: 
              AlertDialog.Builder builder = new Builder(this);
              return builder
                      .setMessage("Are you sure you want to reset the count?")
                      .setNegativeButton("No", new DialogInterface.OnClickListener() {    
  
                          @Override
                          public void onClick(DialogInterface arg0, int arg1) {
                              Toast.makeText(MainActivity.this, "Did not reset!", 5).show();
  
                          }
                      })
  
                      .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  
  
                          @Override
                          public void onClick(DialogInterface arg0, int arg1) {
                              Toast.makeText(MainActivity.this, "Did Reset!", 5).show();
  
                          }
                      })
                      .create();
          }
          return null;
      };
  </code></pre>
  
  <p>Then created a MainDialog class: (I am actually lost in how to do this correctly or apply it)</p>
  
  <pre><code>package com.proteintracker;
  
  import android.support.v4.app.DialogFragment;
  
  public class MainDialog extends DialogFragment {
      public static MyAlertDialogFragment newInstance(int title) {
          MyAlertDialogFragment frag = new MyAlertDialogFragment();
          Bundle args = new Bundle();
          args.putInt("title", title);
          frag.setArguments(args);
          return frag;
      }
  }
  </code></pre>
  
  <p>I am not sure if I was suppose to create a new class for the fragment and how to apply it to my current dialog in the activity screen.</p>