title: display textview in alert dialog
body: <p>In my code, I have an <code>AlertDialog</code> and a <code>TextView</code>. I'd like display this <code>TextView</code>in my <code>AlertDialog</code> but I don't know how to do it. I don't know how to add the <code>View</code> in a <code>AlertDialog</code>.</p>
  
  <p>I could show my code but I don't think it would be usefull.</p>
  
  <p>Thank's</p>
  
  <p>EDIT:</p>
  
  <p>Thank's for all your answers. I just did a test and it works perfectly.</p>
  
  <p>Here is my working code:</p>
  
  <pre><code>package com.example.testalertdialog;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.os.Bundle;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
      LinearLayout layout;
      AlertDialog ad;
      TextView tv1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          layout = new LinearLayout(this);
          ad = new AlertDialog.Builder(this).create();
          tv1 = new TextView(this);
          setContentView(layout);
          tv1.setText("Test");
          ad.setView(tv1);
          ad.show();
  
      }
  }
  </code></pre>
  
  <p>Edit2: But why doesn't this code work ? </p>
  
  <pre><code>package com.example.testalertdialog;
  
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  @SuppressLint("HandlerLeak")
  public class MainActivity extends Activity implements OnClickListener{
  
      LinearLayout layout;
      AlertDialog ad;
      TextView tv1;
      Button b1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          layout = new LinearLayout(this);
          tv1 = new TextView(this);
          b1 = new Button(this);
          b1.setOnClickListener(this);
          layout.addView(b1);
          ad = new AlertDialog.Builder(this).create();
          setContentView(layout);
          tv1.setText("Test");
  }
  
      @Override
      public void onClick(View v) {
          if (v == b1) {
  
          ad.setMessage("Chargement");
          ad.show();
          ad.setView(tv1);
      }
  }
  </code></pre>
  
  <p>}</p>