title: Fragments, how to start Dialog from fragment?
body: <p>i read <a href="http://developer.android.com/reference/android/app/DialogFragment.html" rel="nofollow">DialogFragment</a>, and make one in one like this. </p>
  
  <pre><code>import android.app.AlertDialog;
  import android.app.Dialog;
  import android.content.DialogInterface;
  import android.os.Bundle;
  import android.support.v4.app.DialogFragment;
  
  public class MyDialogFragment extends DialogFragment {
  public static MyDialogFragment newInstance(int title) {
      MyDialogFragment frag = new MyDialogFragment();
      Bundle args = new Bundle();
      args.putInt("title", title);
      frag.setArguments(args);
      return frag;
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
      int title = getArguments().getInt("title");
  
      return new AlertDialog.Builder(getActivity())
              .setIcon(R.drawable.plus_icon)
              .setTitle(title)
              .setPositiveButton("OK",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                          AddExerciseFragment.doPositiveClick();
                      }
                  }
              )
              .setNegativeButton("NO",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                         AddExerciseFragment.doNegativeClick();
                      }
                  }
              )
              .create();
  }
  
  }
  </code></pre>
  
  <p>and in another SherlockFragment i make next:</p>
  
  <pre><code>public void doPositiveClick() {
  
  
  }
  
  public  void doNegativeClick() {
  
  
  }
  void showDialog() {
      DialogFragment newFragment = MyDialogFragment.newInstance(
              R.string.name);
      newFragment.show(getFragmentManager(), "dialog");
  }
  </code></pre>
  
  <p>But methods doPositiveClick(),doNegativeClick() wants to be static - it is bad for me. </p>
  
  <pre><code>public void doPositiveClick() {
      DialogFlag = 0;
      Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
      photoPickerIntent.setType("image/*");
      startActivityForResult(photoPickerIntent, GALLERY_REQUEST);
      // dialog.cancel();
  
  }
  
  
  @Override
  public void onActivityResult(int requestCode, int resultCode,
          Intent imageReturnedIntent) {
      super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
      String path = null;
      if (DialogFlag == 0) {
  
  
          switch (requestCode) {
          case GALLERY_REQUEST:
              if (resultCode == RESULT_OK) {
                  Uri selectedImage = imageReturnedIntent.getData();
                  path = getRealPathFromURI(selectedImage);
                  Log.d("myLogs", path);
                  if (btnID == 1) {
                      pathOne = path;
                      Bitmap bmImg = BitmapFactory.decodeFile(pathOne);
                      ivOne.setImageBitmap(bmImg);
                      one = bmImg;
                  } else {
                      pathTwo = path;
                      Bitmap bmImg = BitmapFactory.decodeFile(pathTwo);
                      ivTwo.setImageBitmap(bmImg);
                      two = bmImg;
                  }
  
              }
          }
      }
      if (DialogFlag == 1) {
          Uri uri;
          if (requestCode == CAMERA_RESULT) {
              Cursor cursor = getActivity().getContentResolver().query(
                      Media.EXTERNAL_CONTENT_URI,
                      new String[] { Media.DATA, Media.DATE_ADDED,
                              MediaStore.Images.ImageColumns.ORIENTATION },
                      Media.DATE_ADDED, null, "date_added ASC");
              if (cursor != null &amp;&amp; cursor.moveToFirst()) {
                  do {
                      uri = Uri.parse(cursor.getString(cursor
                              .getColumnIndex(Media.DATA)));
                      path = uri.toString();
                  } while (cursor.moveToNext());
                  cursor.close();
              }
              Log.d("myLogs", path);
              if (btnID == 1) {
                  pathOne = path;
                  Bitmap bmImg = BitmapFactory.decodeFile(pathOne);
                  ivOne.setImageBitmap(bmImg);
                  one = bmImg;
              } else {
                  pathTwo = path;
                  Bitmap bmImg = BitmapFactory.decodeFile(pathTwo);
                  ivTwo.setImageBitmap(bmImg);
                  two = bmImg;
              }
  
          }
      }
  }
  </code></pre>