Code example for DialogFragment

0
import android.util.Log; 
import android.view.View; 
import android.widget.EditText; 
import android.widget.Toast; 
 
public class SampleDialogFragment extends DialogFragment implements
    DialogInterface.OnClickListener {
  private View form=null;
 
  @Override 
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    form=
        getActivity().getLayoutInflater()
                     .inflate(R.layout.dialog, null);
 
    AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
 
    return(builder.setTitle(R.string.dlg_title).setView(form)
                  .setPositiveButton(android.R.string.ok, this)
                  .setNegativeButton(android.R.string.cancel, null).create());