I have a custom dialog setup and inside it is a button
that I would like to put functionality into, like going to the next Activity or in this case dismiss the dialog. However when I click it its returning a Null reference exception.
Here is my code so far:
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="@+id/image" />
</RelativeLayout>
Activity code:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate {
Dialog dialog = new Dialog(this);
dialog.SetContentView(Resource.Layout.dialog);
dialog.SetTitle("Titolo");
Button dialogbutton = FindViewById<Button>(Resource.Id.dialogButtonOK);
dialogbutton.Click += delegate
{
dialog.Dismiss();
};
dialog.Show();
};
}
}
I have properly referenced the button inside my dialog by using Button dialogbutton = FindViewById<Button>(Resource.Id.dialogButtonOK);
but its throwing a Null Reference Exception.
Im new to Android programming and I would be grateful if anyone could be kind enough to point out what I am doing wrong here.