title: Adding a fragment to a dialog
body: <p>I would like to add a fragment to a dialog (it can be either a DialogFragment or a regular Dialog). How do I do that?</p>
  
  <p>Here's my DialogFragment:</p>
  
  <pre><code>public class MyDialogFragment extends DialogFragment {
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          MyDialogFragment2 dialog = new MyDialogFragment2();
          View v = inflater.inflate(R.layout.news_articles, container, false);
          getActivity().getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, dialog).commit();
          return v;
      }
  
  }
  </code></pre>
  
  <p>Here's news_article.xml:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/fragment_container"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>Here's my main activity: </p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
              MyDialogFragment dialog = new MyDialogFragment();
              dialog.show(getSupportFragmentManager(), "asdf");
          }
      });
  }
  </code></pre>
  
  <p>But when I try it I get:</p>
  
  <pre><code>No view found for id 0x7f070002 for fragment MyDialogFragment2
  </code></pre>
  
  <p>I think it's because the FragmentManager of the Activity isn't the one I should be adding to, but I can't find the one of the DialogFragment, where is it?</p>