title: Accessing DialogFragment Views from another activity
body: <p>I have a class that extends <code>DialogFragment</code> that uses a layout inflater to display different views</p>
  
  <pre><code>public class MyDialog extends DialogFragment {
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState){
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      LayoutInflater layoutInflater = getActivity().getLayoutInflater();
      builder.setView(layoutInflater.inflate(R.layout.dialog_pin_layout,null))
              .setTitle("Enter info")
              ...
      return builder.create();
  }
  </code></pre>
  
  <p>The layout contains only an <code>EditText</code> :</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;EditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/infoEdit" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now I'm trying to auto-fill this <code>EditText</code> from my MainActivity</p>
  
  <pre><code>//When the user clicks on the button in the main activity, prompt MyDialog
  ImageButton usr = (ImageButton)findViewById(R.id.usrImageButton);
  
   usr.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              new MyDialog().show(getFragmentManager(),"fragment_info");
  
              //If userInfo exists, fill the DialogFragment's EditText
              if(userInfo!=null){
                 EditText txt = (EditText)findViewById(R.id.infoEdit);
                 txt.setText(userInfo.toString());
              }
          }
      });
  </code></pre>
  
  <p>When I run the app, clicking the button throws a NullPointerException caused by : <code>txt.setText(userInfo.toString());</code>.
  By using the debugger, I found out that <code>(EditText)findViewById(R.id.infoEdit)</code> returns <code>null</code>, I guess that I'm not able to access the EditText View within my MainActivity by using <code>findViewById</code>. Is there a way to do so ?</p>