title: DialogFragment doesn't show up
body: <p>At the last, I found what the problem is...</p>
  
  <p>If you have a function like this:</p>
  
  <pre><code>public void test()
  {
      DialogFragment dlg = new LoginDialog();
      dlg.show(getSupportFragmentManager(), "login");
  }
  </code></pre>
  
  <p>The dialog will only appear when test() finished, I'm not sure if this is the only way Android dialog works but I'll definitely read more on this...</p>
  
  <hr>
  
  <p><strong>Original Question:</strong></p>
  
  <p>I'm new to android world, can somebody shed some light?</p>
  
  <p>dlg.show() executed without exception but just nothing happens, what should I do to know what's wrong? The project is using Android 2.2's API.</p>
  
  <pre><code>public class MainActivity extends FragmentActivity
  {
      ...
      DialogFragment dlg = new LoginDialog();
      dlg.show(getSupportFragmentManager(), "login");
  }
  </code></pre>
  
  <p>The dialog layout:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"&gt;
  &lt;EditText
      android:id="@+id/username"
      android:inputType="textEmailAddress"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="16dp"
      android:layout_marginLeft="4dp"
      android:layout_marginRight="4dp"
      android:layout_marginBottom="4dp"
      android:hint="username" /&gt;
  &lt;EditText
      android:id="@+id/password"
      android:inputType="textPassword"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="4dp"
      android:layout_marginLeft="4dp"
      android:layout_marginRight="4dp"
      android:layout_marginBottom="16dp"
      android:hint="password"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The dialog class:</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;
  import android.view.LayoutInflater;
  
  public class LoginDialog extends DialogFragment
  {
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState)
      {
          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
          // Get the layout inflater
          LayoutInflater inflater = getActivity().getLayoutInflater();
  
          // Inflate and set the layout for the dialog
          // Pass null as the parent view because its going in the dialog layout
          builder.setView(inflater.inflate(R.layout.login_dialog, null))
          // Add action buttons
                 .setPositiveButton("Sign In", new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
                         // sign in the user ...
                     }
                 })
                 .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
                          // do something
                     }
                 });
          return builder.create();
      }
  }
  </code></pre>