title: Creating listener of a CustomDialog out of the class in Android
body: <p>I am trying to create a listener of a button of a customdialog which extends DialogFragment class and I want to locate the listener of custom buttons out of customdialog fragment class .However when I try to call the view of CustomDialog Fragment then I am getting null exception. What I do is to create an new instance of the customdialog fragment in somewhere else and say</p>
  
  <p>customdialog.getView().findViewById(R.id.custombutton);</p>
  
  <p>but I am getting null.</p>
  
  <pre><code>public class CustomDialog extends DialogFragment {
  
  public  final int RES_NONE = -1;
  private  TextViewCustomFont dialogTitle, view2, dialogBodyBottom,
          dialogBodyTop;
  private  EditTextCustomFont dialogEditText;
  private  ButtonCustomFont dialogLeftButton;
  private ButtonCustomFont dialogRightButton;
  private  Typeface GothamBold, GothamMedium, GothamUltra;
  private static  int title1, bodyTop1, bodyBottom1, EditTextHint1,
          leftButton1, rightButton1;
  onSubmitListener mListener;
  
  private  Dialog dialog;
  
  interface onSubmitListener {
      void setOnSubmitListener(String arg);
  }
  
  public static CustomDialog newInstance(int title, int bodyTop,
          int bodyBottom, int EditTextHint, int leftButton, int rightButton) {
  
      title1 = title;
      bodyTop1 = bodyTop;
      bodyBottom1 = bodyBottom;
      EditTextHint1 = EditTextHint;
      leftButton1 = leftButton;
      rightButton1 = rightButton;
  
      CustomDialog frag = new CustomDialog();
  
  
  
      return frag;
  }
  
  public ButtonCustomFont getDialogLeftButton() {
      return dialogLeftButton;
  }
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
  
      dialog = new Dialog(getActivity());
      dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
      dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
      //dialog.setContentView(R.layout.dialog_layout);
      //dialog.show();
  
      initLayout();
  
      return dialog;
  }
  
  private void initLayout(){
      dialog.setContentView(R.layout.dialog_layout);
      setDialogView();
      setCustomDialog();
  }
  
  public void setDialogView(){    
  
      //Create an java object of each dialog view item
      dialogTitle = (TextViewCustomFont) dialog.findViewById(R.id.custom_dialog_title);
      dialogBodyTop = (TextViewCustomFont) dialog.findViewById(R.id.custom_dialog_body_top);
      dialogBodyBottom = (TextViewCustomFont) dialog.findViewById(R.id.custom_dialog_body_bottom);
      dialogEditText = (EditTextCustomFont) dialog.findViewById(R.id.custom_dialog_body_et);
      dialogLeftButton = (ButtonCustomFont) dialog.findViewById(R.id.custom_dialog_body_btn_left);
      dialogRightButton = (ButtonCustomFont)  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class LoginSelectionFragment extends Fragment {
  
  
  public static LoginSelectionFragment newInstance() {
  
      LoginSelectionFragment fragment = new LoginSelectionFragment();
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_loginselection,
              container, false);
  }
  </code></pre>
  
  <p>I am trying to pull the dialogLeftButton of CustomDialog Fragment and assing a listener on it inside the LoginSelectionFragment. </p>
  
  <p>Here is how it looks like after I added method 2. This a part of LoginSelectionFragment</p>
  
  <pre><code>private void TwoButtonTextEditTextDialog(){
      String title = getResources().getString(R.string.invalid_info_header);
      String body = getResources().getString(R.string.invalid_info_body);
      String body2 = getResources().getString(R.string.hint_newemail);
      String btn1 = getResources().getString(R.string.cancel_uppercase);
      String btn2 = getResources().getString(R.string.ok_alert);
  
      fragmentDialog = CustomDialog.newInstance(title, body, body2, RES_NONE, btn1, btn2);
      fragmentDialog.setCustomDialogFragmentListener(mDialogClickListener);
      fragmentDialog.show(getFragmentManager(), "");
  }
  
  private  CustomDialog.CustomDialogFragmentListener mDialogClickListener = new CustomDialog.CustomDialogFragmentListener(){ 
  
      @Override
      public void onNegativeClick() {
      // TODO Auto-generated method stub
      fragmentDialog.dismiss();
      }
  
      @Override
      public void onPositiveClick() {
      // TODO Auto-generated method stub
      fragmentDialog.dismiss();
      }
  
  };
  
  
  @Override
  public void onNegativeClick() {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void onPositiveClick() {
      // TODO Auto-generated method stub
  
  }
  </code></pre>