title: Start Dialog for result to return value to main activity
body: <p>I have been trying to get my head around this for a couple of hours now.</p>
  
  <p>I have a main Fragment class, then from the onClick I have set up from an ImageView in that class , I am starting a Dialog Fragment with a simple "Yes" or "Cancel" option. </p>
  
  <p>How would I make it so that when the user clicks "Ok", it will then send a Result code back to my main Fragment telling it to run some code(In my case, I am setting wallpaper).</p>
  
  <p>This sound simple but can't seem to figure it out. Thanks in advance.</p>
  
  <p>Onclick where I would like to somehow get the result back to:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      final View v = inflater.inflate(R.layout.image_detail_fragment,
              container, false);
  
      mImageView = (RecyclingImageView) v.findViewById(R.id.imageView);
      mImageView.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
  
              MyDialogFragment dialog = new MyDialogFragment();
              dialog.show(getActivity().getFragmentManager(),
                      "MyDialogFragment");
  
          }
  
          public void onDialogOKPressed() {
  
      ((ImageDetailFragment) (DialogFragment.this.getParentFragment()))
                      .onDialogOKPressed();
              dismiss();
  
          }
      });
  
      return v;
  }
  </code></pre>
  
  <p>Dialog class:</p>
  
  <pre><code>class MyDialogFragment extends DialogFragment {
      private Button ButtonOk;
      private Button ButtonCancel;
  
      public MyDialogFragment() {
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.prompt, container);
          ButtonOk = (Button) view.findViewById(R.id.button1);
          ButtonCancel = (Button) view.findViewById(R.id.button2);
          getDialog().setTitle("Set Wallpaper?");
  
          ButtonOk.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
                                                  ((MyDialogFragment)(DialogFragment.this.getActivity())).onDialogOKPressed();
                  dismiss();
  
  
              }
  
          });
  
          ButtonCancel.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
                  MyDialogFragment.this.dismiss();
  
              }
          });
  
          return view;
  
      }
  }
  </code></pre>