title: Android dialog with custom layout: returning data
body: <p>I have problem with getting data, that user inputs in <code>dialog</code> (with custom layout). Look at the code:</p>
  
  <p>unit.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;EditText
      android:id="@+id/editText1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  &lt;/EditText&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>    AlertDialog.Builder builder = new AlertDialog.Builder(this);
      LayoutInflater inflater = this.getLayoutInflater();
      builder.setView(inflater.inflate(R.layout.unit, null)); 
      AlertDialog dialog = builder.create();
      dialog.show();
  </code></pre>
  
  <p><code>Dialog</code> opens with layout I have created, but that</p>
  
  <pre><code>    builder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                          EditText text = (EditText)findViewById(R.id.editText1);
                          Toast.makeText(getApplicationContext(), text.getText(), Toast.LENGTH_SHORT).show();
              dialog.dismiss();
            }
  
          });
  </code></pre>
  
  <p>produces runtime error: <code>java.lang.NullPointerException</code>. Where is the problem?</p>