title: EditText in custom Android Dialog returns null
body: <p>So I created a custom dialog as per the current guide on the Android Developer website (<a href="http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout" rel="nofollow">http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout</a>), and wish to pass back the user input from the EditText to MainActivity; but it turns out MainActivity receives null. I can't see why.</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Here's my code:</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements NewItemFragment.NoticeDialogListener {
  
  private final static String TAG = "tag";
  
  RecyclerView recyclerView;
  RecyclerView.LayoutManager manager;
  RecyclerView.Adapter adapter;
  FloatingActionButton fab;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      fab = (FloatingActionButton) findViewById(R.id.fab);
  
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              NewItemFragment dialog = new NewItemFragment();
              dialog.show(getSupportFragmentManager(), "newitem");
          }
      });
  
      manager = new LinearLayoutManager(this);
  
      recyclerView = (RecyclerView) findViewById(R.id.recycler);
      recyclerView.setLayoutManager(manager);
  
      initialiseData();
      initialiseAdapter();
  }
  
  @Override
  public void onDialogPositiveClick(DialogFragment dialogFragment) {
      LayoutInflater inflater = getLayoutInflater();
      View view = inflater.inflate(R.layout.new_item_dialog, null);
      EditText editText = (EditText) view.findViewById(R.id.newitem);
      String input = editText.getText().toString();
      EditText result = (EditText) findViewById(R.id.textedit);
      int i = entries.size();
      if (input.equals("")) {
          result.setText("Fail");
      } else {
          entries.add(new Items(input));
          adapter.notifyItemInserted(i + 1);
      }
  }
  
  @Override
  public void onDialogNegativeClick(DialogFragment dialogFragment) {
  }
  </code></pre>
  
  <p>}</p>
  
  <p>NewItemFragment.java</p>
  
  <pre><code>public class NewItemFragment extends DialogFragment {
  
  public interface NoticeDialogListener {
      public void onDialogPositiveClick(DialogFragment dialogFragment);
      public void onDialogNegativeClick(DialogFragment dialogFragment);
  }
  
  NoticeDialogListener listener;
  
  @Override
  public void onAttach(Activity activity) {
      super.onAttach(activity);
      try {
          listener = (NoticeDialogListener) activity;
      } catch (ClassCastException e) {
          throw new ClassCastException(activity.toString()
              + " must implement NoticeDialogListener");
      }
  }
  
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      final LayoutInflater inflater = getActivity().getLayoutInflater();
      final View view = inflater.inflate(R.layout.new_item_dialog, null);
      builder.setView(view)
              .setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      listener.onDialogPositiveClick(NewItemFragment.this);
                  }
              })
              .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      NewItemFragment.this.getDialog().cancel();
                  }
              });
      return builder.create();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And finally new_item_dialog.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingTop="24dp"
      android:paddingStart="24dp"
      android:paddingEnd="24dp"&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="24sp"
          android:textColor="#000000"
          android:text="@string/new_item"
          android:layout_marginBottom="20dp"/&gt;
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/newitem"
          android:hint="@string/hint"
          android:layout_marginBottom="24dp"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Thanks,
  Josh</p>