title: Android Fragment in alert dialog
body: <p>I am making a search page for an android application.  I want to add some search filters in some sort of modal and the suggestions on the internet say I should use an AlertDialog with a fragment to show my custom filters.  I have managed to get the fragment to show in the dialog but the code associated with the fragment such as onCreate is not being called.  When I use the fragment directly in an activity its onCreate gets called but not when it is being loaded by the AlertDialog.  Is there something I am doing wrong or should I be doing this another way?</p>
  
  <p>This is the code used to open the dialog</p>
  
  <pre><code>SearchFilterDialogFragment dialog = new SearchFilterDialogFragment();
              FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
              Fragment prev = getFragmentManager().findFragmentByTag("dialog");
              if (prev != null) {
                  fragmentTransaction.remove(prev);
              }
              fragmentTransaction.addToBackStack(null);
              dialog.show(fragmentTransaction,"dialog");
  </code></pre>
  
  <p>This is the code for the dialog configuration</p>
  
  <pre><code>public class SearchFilterDialogFragment extends DialogFragment {
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
  
      // Use the Builder class for convenient dialog construction
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      LayoutInflater inflater = getActivity().getLayoutInflater();
  
      builder.setView(inflater.inflate(R.layout.fragment_blank,null)).setTitle("Search Filters")
              .setPositiveButton(R.string.filter_dialogue_ok, new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                      // FIRE ZE MISSILES!
                  }
              })
              .setNegativeButton(R.string.filter_dialogue_cancel, new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                      // User cancelled the dialog
                  }
              });
  
      return builder.create();
  
  
  
  }
  </code></pre>
  
  <p>This is the test fragment that will eventually have actual filters in it</p>
  
  <pre><code>public class BlankFragment extends Fragment {
  
  
  
  public BlankFragment() {
      // Required empty public constructor
  }
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      return inflater.inflate(R.layout.fragment_blank, container, false);
  }
  </code></pre>
  
  <p>}</p>