title: Problems with buttons in a Dialog
body: <p>I have a custom Dialog that shows a few buttons.  The idea is to have a scrollable Dialog where one can choose a number or letter from 0 to 9, or 0 to F or 0 to Z ...</p>
  
  <p>So my first problem is how do I add these buttons through code and not xml since there is a variable number of buttons each time.  Even the simplest code crashes on me so I'm probably not doing anything right.</p>
  
  <p>Also the code I have with a few xml buttons chrashes when I click on the buttons saying it can't find the onClick function.  As you can see I have android:onClick="onClickDialogbutton" in my button xml and the function does exist in my java code but still it crashes.</p>
  
  <p>Hope someone can take look at the code and help me with adding buttons programatically and get the onClick to work.</p>
  
  <p>Here is my code:</p>
  
  <p>DialogTestActivity.java:</p>
  
  <pre><code>package com.test.dialog;
  import android.app.Activity;
  import android.app.Dialog;
  import android.os.Bundle;
  import android.view.View;
  import android.view.Window;
  import android.widget.Button;
  import android.widget.LinearLayout;
  public class DialogTestActivity extends Activity {
      Dialog dialog;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
      }
      public void onClickStartDialog( View view ) {
          dialog = new Dialog( this );
          dialog.requestWindowFeature( Window.FEATURE_NO_TITLE );
          dialog.setContentView( R.layout.dialog );
          dialog.setCancelable( true );
          dialog.show();
          // I here wish to add buttons through code and not xml.
          // This gives an error as it is now.
          Button button = new Button( this );
          ( ( LinearLayout )findViewById( R.id.Buttons ) ).addView( button );
      }
      public void onClickDialogButton( View view ) {
          dialog.dismiss();
      }
  }
  </code></pre>
  
  <p>Main.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="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:onClick="onClickStartDialog"
          android:text="Start Dialog" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Dialog.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="54dip"
      android:layout_height="150dip"
      android:gravity="center" &gt;
      &lt;ScrollView
          android:layout_width="48dip"
          android:layout_height="144dip" &gt;
          &lt;LinearLayout
              android:id="@+id/Buttons"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical" &gt;
              &lt;Button
                  android:id="@+id/ButtonId0"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_horizontal"
                  android:onClick="onClickDialogbutton"
                  android:text="0"
                  android:textSize="32dip" /&gt;
              &lt;Button
                  android:id="@+id/ButtonId1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_horizontal"
                  android:onClick="onClickDialogbutton"
                  android:text="1"
                  android:textSize="32dip" /&gt;
              &lt;Button
                  android:id="@+id/ButtonId2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center_horizontal"
                  android:onClick="onClickDialogbutton"
                  android:text="2"
                  android:textSize="32dip" /&gt;
              &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>