title: AlertDialog.Builder with custom layout and EditText; cannot access view
body: <p>I am trying to create an alert dialog with an <code>EditText</code> object. I need to set the initial text of the <code>EditText</code> programmatically. Here's what I have.</p>
  
  <pre><code>AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
  // ...Irrelevant code for customizing the buttons and title
  AlertDialog alertDialog = dialogBuilder.create();
  LayoutInflater inflater = this.getLayoutInflater();
  alertDialog.setContentView(inflater.inflate(R.layout.alert_label_editor, null));
  EditText editText = (EditText) findViewById(R.id.label_field);
  editText.setText("test label");
  alertDialog.show();
  </code></pre>
  
  <p>What do I need to change so that I can have a valid <code>EditText</code> object?</p>
  
  <p>[edit]</p>
  
  <p>So, it was pointed out by user370305 and others that I should be using <code>alertDialog.findViewById(R.id.label_field);</code></p>
  
  <p>Unfortunately there is another issue here. Apparently, setting the content view on the <code>AlertDialog</code> causes the program to crash at runtime. You have to set it on the builder. </p>
  
  <pre><code>AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
  // ...Irrelevant code for customizing the buttons and title
  dialogBuilder.setView(inflater.inflate(R.layout.alert_label_editor, null));
  AlertDialog alertDialog = dialogBuilder.create();
  LayoutInflater inflater = this.getLayoutInflater();
  EditText editText = (EditText) alertDialog.findViewById(R.id.label_field);
  editText.setText("test label");
  alertDialog.show();
  </code></pre>
  
  <p>Unfortunately, when you do this, <code>alertDialog.findViewById(R.id.label_field);</code> now returns <code>null</code>.</p>
  
  <p>[/edit]</p>