So I am adding new button to my app but when FindViewById is called it returns null and app crashes. In my .cs file I have following function:
void fooUIButtonHandler()
{
var fooUIButton = FindViewById(Resource.Id.fooUIButton);
fooUIButton.Click += delegate
{
if (!CheckOriginalImage())
{
return;
}
Intent intent = new Intent(this, typeof(fooImageDemoActivity));
intent.PutExtra(fooImageDemoActivity.EXTRAS_ARG_IMAGE_FILE_URI,
originalImageUri.ToString());
StartActivityForResult(intent, REQUEST_SB_FOO_UI);
};
}
and my .axml file looks like this:
<Button
android:id="@+id/fooUIButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0b8442"
style="@style/Widget.AppCompat.Button.Borderless"
android:text="foo"/>
I am setting Content View in OnCreate:
SetContentView(Resource.Layout.FooDocumentCreation);
and then calling:
fooUIButtonHandler()
But following line is throwing Null exception:
var fooUIButton = FindViewById(Resource.Id.fooUIButton);
Any ideas how to fix it?