title: getText from a EditText in a DialogFragment
body: <p>I have a DialogFragment like this one</p>
  
  <p><img src="https://i.stack.imgur.com/87cU9.png" alt="enter image description here"></p>
  
  <p>The Dialog is called by clicking on the "plus" button in the MainActivity below which is initially empty. When I click on "continue", I create a button  and so far it works. I also wish that the string I insert in the EditText in DialogFragment is shown on the button I've just created. My problem is that I can not retrieve the string I entered in the EditText.</p>
  
  <p>Here is the code:</p>
  
  <p>MainActivity</p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements IProjectDialFrag {
  
      private ProjectDialogFragment projectDialFrag = new ProjectDialogFragment();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater inflater = getMenuInflater();
              inflater.inflate(R.menu.main, menu);
          return super.onCreateOptionsMenu(menu);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
  
          switch (id) {
              case R.id.action_settings:
                  //TODO
                  return true;
              case R.id.filters:
                  Intent intent1 = new Intent(MainActivity.this, FiltersActivity.class);
                  startActivity(intent1);
                  return true;
              case R.id.action_new:
                  return true;
              case R.id.add_button:
                  Intent intent2 = new Intent(MainActivity.this, ButtonsActivity.class);
                  startActivity(intent2);
                  return true;
              case R.id.add_project:
                  projectDialFrag.show(getFragmentManager(), "projectDialog");
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
  
      }
  
      @Override
      public void onDialogNegativeClick(DialogFragment dialog) {
          return;
      }
  
      @Override
      public void onDialogPositiveClick(DialogFragment dialog) { 
          LayoutInflater inflater = LayoutInflater.from(this);
          View view = inflater.inflate(R.layout.project_dialog_fragment, null);
  
          EditText editText = (EditText) view.findViewById(R.id.project_name);
          String projectName = editText.getText().toString();
          Button projectButton = new Button(this);
          projectButton.setText(projectName);
          LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main_layout);
          linearLayout.addView(projectButton);
  
      }
  
  }
  </code></pre>
  
  <p>DialogFrament</p>
  
  <pre><code>public class ProjectDialogFragment extends DialogFragment {
  
      private IProjectDialFrag iProjDialFrag;
  
      @SuppressLint("InflateParams")
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
           AlertDialog.Builder createProjectAlert = new AlertDialog.Builder(getActivity());
  
           createProjectAlert.setTitle("Create Project");
  
           LayoutInflater inflater = getActivity().getLayoutInflater();
  
           createProjectAlert.setView(inflater.inflate(R.layout.project_dialog_fragment, null))
  
              .setPositiveButton(R.string.conti_nue, new DialogInterface.OnClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int id) {
                      iProjDialFrag.onDialogPositiveClick(ProjectDialogFragment.this);
                  }
              })
              .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int id) {
                      iProjDialFrag.onDialogNegativeClick(ProjectDialogFragment.this);
  
                  }
              });
  
           return createProjectAlert.create();
  
      }
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
          iProjDialFrag = (IProjectDialFrag) activity;
      }
  
  }
  </code></pre>
  
  <p>The Interface </p>
  
  <pre><code>public interface IProjectDialFrag {
  
      public void onDialogPositiveClick(DialogFragment dialog);
      public void onDialogNegativeClick(DialogFragment dialog);
  
  }
  </code></pre>
  
  <p>and the XML layout for reference:</p>
  
  <p>DialogFragment layout</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical" &gt;
  
      &lt;EditText 
          android:id="@+id/project_name" 
          android:inputType="text"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="16dp"
          android:layout_marginLeft="4dp"
          android:layout_marginRight="4dp"
          android:layout_marginBottom="4dp"
          android:hint="@string/hint_project_alert" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>MainActivity layout</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" 
      android:orientation="horizontal"
      android:id="@+id/main_layout"&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Where am I wrong?</p>